Search code examples
regexapachemod-rewritehttp-redirectmod-alias

Apache Redirect Permanent For URL with Data in String (Question Mark)


I am looking for an Apache redirect where the source URL has a question mark in it.

Redirect permanent /course/view.php?id=68 http://exmaple.com/page.php

I've tried escaping the question mark, but that doesn't work. I've read a couple pages on the web about using Rewrite conditions, however it didn't quite make sense to me, or it was a little bit different than what I wanted to accomplish.


Solution

  • Try adding the following to the .htaccess file in the root directory of your site.

    RewriteEngine on
    RewriteBase / 
    
    RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /course/view\.php\?id=68 [NC]  
    RewriteRule ^ http://exmaple.com/page.php [L,R=301]