The Information:
So I am fairly new to .htaccess and have being reading a bit.
Basically I want to do this, redirect the url www.example.com/center-pro to www.example.com/pro-hq (found how here here .htaccess URL redirect)
However the site i am work on already has a .htaccess file in place.
This is what I am adding doing :
Options +FollowSymLinks #alread开发者_Python百科y in htaccess file
RewriteEngine On #already in htaccess file
Redirect 301 /center-pro http://www.example.com/pro-hq #line I added
RewriteCond %{REQUEST_FILENAME} !-f #already in htaccess file
RewriteCond %{REQUEST_FILENAME} !-d #already in htaccess file
RewriteRule ^(.*) index.php?idstring=$1&%{QUERY_STRING} #already in htaccess file
The last line seems to be messing with my redirect
So the output from my redirect looks like this : www.example.com/pro-hq?idstring=center-pro
The Question:
Is there any way to have the redirect rule above and keep the current .htaccees so I don't mess up the current site settings.
** note: Doing a RewriteRule works but i would like to use a redirect so people don't share the wrong url.
You can use mod_rewrite
for your external redirection too:
RewriteRule ^center-pro$ http://www.example.com/pro-hq [R=301,L]
This is probably the simplest solution, in place of your current Redirect
. The problem is that mod_rewrite
performs its work before mod_alias
, and while the rewritten URI path is not passed along, the modified query string unfortunately is. You could also condition your RewriteRule
to prevent it from processing the path you want handled by mod_alias
, but I prefer the first option:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond ${REQUEST_URI} !^/center-pro
RewriteRule ^(.*) index.php?idstring=$1&%{QUERY_STRING}
Additionally, for your currentRewriteRule
, you can just use the QSA
flag instead of manually appending the query string to the URL:
RewriteRule ^(.*) index.php?idstring=$1 [QSA]
精彩评论