views:

41

answers:

1

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 http://stackoverflow.com/questions/3374696/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  #already 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.

+1  A: 

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]
Tim Stone
Awesome I tired doing a RewriteRule (RewriteRule center-pro pro-hq [L]) before, but the url was just being mask, seems like by adding R=301 the url is changed!The first line worked great, thanks for the depth of info, not going to change to the QSA flag as i didnt write that line.Now I need to go learn what ^ and $ do in htaccess land.Thanks Again
theGoose
@theGoose - No problem. As far as the `^` and `$` go, they're just [regular expression anchors](http://www.regular-expressions.info/anchors.html) for the test patterns, and match the beginning and the end of the input (the current URL without the query string), respectively.
Tim Stone