Forum Moderators: phranque

Message Too Old, No Replies

301 redirect issue ?i parameters

new to the topic, potential syntax problem with .htaccess

         

derevyan

5:55 pm on Jun 21, 2011 (gmt 0)

10+ Year Member



Hello,

I am new to this topic but I have been battling with a redirect for some and quite frankly Im out of ideas.

I have a website and I wold like to permanently redirect some pages but I think Im having problems with the syntax.

I would like to redirect a few pages of the following format:

[mysite...] -> [mysite...]
without the ?i3 part.

here is what I have so far in the .htaccess:

RewriteEngine on
RewriteRule ^page1\.html([^&])$ page1.html [R=301]

I have tried quite a few versions of this, but nothing seems to work!

Please please help! What am i doing wrong?

Thank you in advance for your help!

g1smd

7:46 pm on Jun 21, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Use
example.com
to stop the forum auto-linking the URLs.

That will make the question readable.

Be aware that
RewriteRule
cannot see query string data. It can only see the path part of a URL.

You need to test the
QUERY_STRING
with a preceding
RewriteCond
to see the query string data.

derevyan

4:11 pm on Jun 23, 2011 (gmt 0)

10+ Year Member



Thank you for your answer!

Im doing it for the first time so, to test the query string do you mean something like this?

so for example.com/page1.html?i3 -> example.com/page1.html



RewriteEngine on
RewriteCond %{QUERY_STRING} i3
RewriteRule ^/page1\.html /page1\.html? [R=301]

This still doesn't work, the query is still there....

Any thoughts?

g1smd

7:01 pm on Jun 23, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



You need the [L] flag to stop processing when the rule matches.

Add the domain name to the target URL. Don't escape the period in the target.

If this code goes in .htaccess, the RewriteRule pattern cannot see the leading slash. Delete the leading slash.

lucy24

8:57 pm on Jun 23, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



What does the question mark in the target (html?) mean?

I consulted the horse's mouth [httpd.apache.org] but emerged none the wiser.

g1smd

9:06 pm on Jun 23, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



In RegEx patterns
\.html?
will match
.htm
and
.html
requests.

In a target URL
.html?
stops query string data from the original request being re-appended.