Forum Moderators: phranque
I'm using this :
RewriteCond %{QUERY_STRING} ^p=9$
RewriteRule ^test.php$ http://example.com/bigurl.html [R=301,L]
It works. But the problem is that "?p=9" is appended to destination URL having this for result: http://example.com/bigurl.html?p=9
How could i avoid having the argument added and the end of the URL?
I tryed this :
RewriteCond %{QUERY_STRING} ^p=9$
RewriteRule ^test.php$ - [C]
RewriteRule ^.*$ http://example.com/bigurl.html [R=301,L]
Any ideas?
Thx in advance,
micobros
[edited by: jdMorgan at 3:40 pm (utc) on Sep. 30, 2008]
[edit reason] Pleas use example.com [/edit]
That will clear the query string.
You can also simplify ^.*$ to just .*
Do you want this rule to work for all URLs that have the p=9 parameter (such as /otherpage.html?p=9 for example), or just for the /test.php?p=9 one? You need to make sure you code it right.
You might not need to start anchor or end anchor the query string. It can then also redirect if extra unwanted parameters have been added to the requested URL.
@g1smd: only for one specific URL
@jdMorgan: i agree with you. The test with 2 RewriteRules was to try to get rid of that persistent argument...
Thanks!
See the notes following the RewriteRule directive. The "really good stuff" is in the notes for each directive.
Jim
Yeah, indeed... my bad.
But,
Simply use a question mark inside the substitution string, to indicate that the following text should be re-injected into the query string.
Another little question, in my redirects, i use special chars (ex:'é') :
RewriteCond %{QUERY_STRING} ^cat=7$
RewriteRule ^blog/$ http:/example.com/blog/term/conférence-14? [R=301,NE,L]
I do use, NE, which should not escape the special chars. But it does, and redirects me to: http://example.com/blog/term/r%E9f%E9rencement-11
Any idea on this one?
thanks,
micobros
[edited by: jdMorgan at 1:59 pm (utc) on Oct. 1, 2008]
[edit reason] Please use example.com only [/edit]
This problem is common with sites using non-U.S. character sets. Sorry, but that's a legacy issue from the days when "the internet" was something used only by U.S. defense agencies and their academic partners.
Since I don't have any non-English sites, I have no useful experience with this problem. You might try encoding the special characters yourself using "\%2c25"-style notation in the substitution string. Also make sure your server's default character-set is correctly defined (see mod_mime). If you have a multi-lingual site, it may be helpful to change this definition depending on the <Directory> or <Location> containers used to serve each language (see Apache core).
Again, I have very limited experience with this, and it might be worthwhile to check Webmaster sites in the country whose language you are trying to use for help with these issues if no-one else replies here.
Jim