trante
trante

Reputation: 33996

Redirecting with htaccess

It seems a very eask task, but I couldn't make it for hours after reading too much tutorial. Please help..

I need to redirect

http://example.com/myfolder/myfile.php?type=1&add=20

to this address:

http://example.com/newfolder/mytasks.xml

I tried too many. My last tryout was this:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteRule ^/myfolder/myfile.php?type=1&add=20$ /newfolder/mytasks.xml [R=301,NC,L]
</IfModule>

Upvotes: 1

Views: 52

Answers (2)

Felipe Alameda A
Felipe Alameda A

Reputation: 11809

If you also want the query type=1&add=20 removed, something like this should work:

Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING}  type=1&add=20                 [NC]
RewriteCond %{REQUEST_URI}   !/newfolder/                  [NC]
RewriteRule ^myfolder/myfile\.php  /newfolder/mytasks.xml? [R=301,NC,L]

Redirects:

http://example.com/myfolder/myfile.php?type=1&add=20 to

http://example.com/newfolder/mytasks.xml

For silent mapping, replace [R=301,NC,L] with [NC,L]

Upvotes: 1

anubhava
anubhava

Reputation: 786091

Use this rule instead:

RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+myfolder/myfile\.php\?type=1&add=20 [NC]
RewriteRule ^ /newfolder/mytasks.xml [R=301,L]

Remember:

  • RewriteRule match doesn't start with a slash /
  • RewriteRule doesn't match query string, it matches only Request URI

Upvotes: 1

Related Questions