Forum Moderators: phranque
Does someone knows about this strange behavior find below ?
I have 2 new URLs for 2 pages to redirect, nothing like rocket science...
When I redirect this way :
Redirect 301 /pg/pk_de /pg/pk_de_tt
the Redirect 301 works but the URL is not clean and rewrite this in the Address bar:
http://www.example.com/pg/pk_de_tt?p=pg&id=pk_de
I would like this URL without the ?p=pg&id=pk_de that refers to nothing anymore
My htaccess already had simple rewrite rules like
DirectoryIndex index.php?p=page&id=index
Options +Indexes +MultiViews +FollowSymlinks
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?example.com/.*$ [NC]
RewriteRule \.(gif¦jpg¦swf¦flv¦png)$ /feed/ [R=302,L]
RewriteCond %{HTTP_HOST} !^www.example.com$
RewriteRule ^(.*) http://www.example.com/$1 [R=301]
RewriteRule ^index.html /index.php
RewriteRule ^([^/.]+)/([^/.]+)/?$ index.php?p=$1&id=$2
RewriteRule ^([^/.]+)/([^/.]+)/([^/.]+)/?$ index.php?p=$1&id=$2&edito=$3
RewriteRule ^([^/.]+)/?$ index.php?p=$1
The question is How can I get a clean URL redirect without the QUERY_STRING ?
Remember that query strings are not part of a URL. They have no function in "locating" any resource. They are data appended to a URL to be passed to the resource at that URL. Therefore Apache directives which manipulate URLs do not even 'see' the query string, and query strings must be handled separately. For example, see the RewriteCond documentation and the %{QUERY_STRING} and %{THE_REQUEST} environment variables.
Use this rule to implement your redirect and clear the query string:
RewriteRule ^pg/pk_de$ http://www.example.com/pg/pk_de_[b]tt?[/b] [R=301,L]
Do not mix "Redirect" and other mod_alias directives with mod_rewrite directives; Doing so means you cannot control the order of execution of your directives: Either mod_alias or mod_rewrite may execute first, depending on your server configuration, and that could change if you switch hosts or if your server is upgraded, breaking your code.
Add an [L] flag to all of your rules. [L] should always be used, unless you know why you do not want to use it in a specific case.
Keep all of your external redirects ahead of all of your internal rewrites, and put the rules in each of these two groups in order from most-specific patterns and conditions (fewest URLs affected) to least-specific (most URLs affected).
For example, your current third rule (which should be a redirect, not a rewrite as shown), should go before your current second rule. I would suggest that you replace your current third rule with
RewriteRule ^index\.html$ http://www.example.com/ [R=301,L]" The new rule I gave above you should go ahead of your current first or second rule (in this case it doesn't matter because they are mutually-exclusive).
Escape all literal periods in your regex patterns. For example, "!^www.example.com$" should be "!^www\.example\.com$"
Jim