Forum Moderators: phranque
Rewritecond %{query_string} ^letter=(.*)$
RewriteRule ^folder/([^/]*)/alphabet$ /folder2/$1/%1 [R=301,L]
I'd like this:
[mysite.com...] -->
[mysite.com...]
What I get instead is: [mysite.com...]
So basically I can't get rid of the query string.
Thanks,
Storm
;)
One, go by the book on everything -- Do NOT feel free to change anything from the examples you see at apache.org -- Type the directives and variable names exactly as shown to avoid compatibility/portability problems; mod_rewrite is not a "forgiving" or flexible general-purpose programming language.
Two, make your patterns as specific as possible. This may improve performance, prevent unexpected results, and make it easier to maintain your code. For example, your rule may fail if you ever add another query string parameter ahead of or behind "letter", or if someone links to you with a double slash after "folder".
Try:
RewriteCond %{QUERY_STRING} &?letter=([^&]+)&?
RewriteRule ^folder/([^/]+)/alphabet$ /folder2/$1/%1? [R=301,L]
Jim
"This is absolutely correct according to the documentation and I've tested it thoroughly" is a much more robust approach to configuring your server than "It seems to work fine." It is possible to make a very good living correcting the unintended functional and search ranking consequences of "only-slightly-incorrect" coding in server config files...
Jim
You might have some other rule that fixes up non-www requests by redirecting them to www.domain.com but that will lead to a redirection chain, two back-to-back redirects.
So, you fix that by making sure that while redirecting the specific filename, you also fix the domain at the same time in the same redirect.
Your generic non-www to www 301 redirect will be placed after the specific-filename rule in your .htaccess file and it will catch all of the other non-www requests.
Your Duplicate Content issue, and the redirection chain have now both been designed out.
I'm wondering: if I get rid of my old "double" 301 redirects (by redirecting A directly to C), will PR be restored?
Thanks
A rewrite connects a URL request to an internal filepath that is different to the one that would normally be expected from the URL request.
A request for domain.com/file.html is rewritten to pull some other file, such as other.html, from the server, without exposing the name or path of that file.
A rewrite will NOT include the domain name and will not include a R=nnn parameter either.
Note: Including the domain name always makes it a 302 redirect unless you also add R=301 to make it a 301 redirect.
A rewrite internally rewrites a URL request to an alternative internal filepath, something like:
RewriteRule ^file.html /elsewhere/other.html [L]
Rewrites must always be placed after all of your redirects, otherwise you risk exposing the internal filepath as a new URL.
[edited by: g1smd at 8:43 pm (utc) on Aug. 14, 2008]
Rewrites must always be placed after all of your redirects, otherwise you risk exposing the internal filepath as a new URL
What about non-www->www?
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
Should it be at the very bottom of all redirect requests?
Rewrites silently pull the content from the server, but from a different place in the filesystem to what may have been expected. The filepath should not be exposed.
If you put redirects after rewrites you risk exposing the supposedly secret internal filepath to the outside world.