custom 301 redirects from old joomla (mambo) websi

2019-08-29 08:05发布

问题:

The past couple of hours I am trying to create custom redirects from an old mambo website to new drupal 7 website with the .htaccess file that exists in my drupal's root. What I want to do is...

301 Redirect

http://mysite.com/index.php?option=com_content&task=blogsection&id=11&Itemid=54

to

http://mysite.com/this-is-the-new-page

This is my .htaccess file...

RewriteEngine on

RewriteRule ^index.php?option=com_content&task=blogsection&id=11&Itemid=54$ http://mysite.com/this-is-the-new-page [R=301,L]

RewriteRule "(^|/)\." - [F]

RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [L,R=301]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^ index.php [L]

I am sure that it has something to do with this line...

RewriteRule ^ index.php [L]

But I don't get it! You see if I use this...

RewriteRule ^option=com_content&task=blogsection&id=11&Itemid=54$ http://mysite.com/this-is-the-new-page [R=301,L]

instead of this...

RewriteRule ^index.php?option=com_content&task=blogsection&id=11&Itemid=54$ http://mysite.com/this-is-the-new-page [R=301,L]

and test it with firefox and LiveHTTP Headers addon it works!

Any suggestions?!

Thanks!

回答1:

The query string is not part of the URL path pattern. If you want to base a rule on the query string, you must do so in a RewriteCond

RewriteEngine on
RewriteCond %{QUERY_STRING} option=com_content&task=blogsection&id=11&Itemid=54
RewriteRule ^index.php$ /this-is-the-new-page? [R,L]