Forum Moderators: phranque

Message Too Old, No Replies

How to detect GET ID and rewrite?

         

toplisek

11:59 am on Feb 10, 2011 (gmt 0)

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



I need to detect GET ID for page and rewrite to my search frindly URL.
I tried to do with the following but it does not detect code:



RewriteCond %{QUERY_STRING} id=(.*)
RewriteRule ^sales/index.php?id=short /Amazonsalesarticles/mysefriendlypage.html




Why is not detected GET ID short and changed to page name
/Amazonsalesarticles/mysefriendlypage.html

How to add also redirection if URL has name like:
sales/index.php?id=short

Redirection is to


http://www.mydomain.com/Amazonsalesarticles/mysefriendlypage.html

wilderness

3:59 pm on Feb 10, 2011 (gmt 0)

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



php?id [google.com]

g1smd

7:22 pm on Feb 10, 2011 (gmt 0)

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



RewriteRule cannot "see" query string data.

You need that preceding
RewriteCond
looking at
%{QUERY_STRING}
to do that, but must not repeat the query string data in the RewriteRule pattern.

Add the
[L]
flag if this is an internal rewrite.

Add the
[R=301,L]
flags if this is a redirect.

toplisek

8:13 pm on Feb 10, 2011 (gmt 0)

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



Will this work?
RewriteCond %{QUERY_STRING} id=(.*)
Redirect permanent /sales/index.php?id=short /Amazonsalesarticles/mysefriendlypage.html [R,L]


What is definition of internal and what redirect?
Is base server and its files to outside EXTERNAL server (domain)?

g1smd

8:42 pm on Feb 10, 2011 (gmt 0)

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



No it will not work.

You cannot use
RewriteCond
and
Redirect
together.
RewriteCond
goes only with
RewriteRule
.

Use a
RewriteRule
, but do not include the query string in the
RewriteRule
pattern.

With the
[R]
flag you have invoked a 302 "temporary" redirect.

You probably need the
[R=301,L]
flags here in order to invoke a 301 "permanent" redirect.

The redirect instructs the browser to make a new request for a different URL.

jdMorgan

7:42 pm on Feb 17, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member




# Redirect requests for /sales/index.php?id=short to www.example.com/Amazonsalesarticles/mysefriendlypage.html
RewriteCond %{QUERY_STRING} ^id=short$
RewriteRule ^sales/index\.php$ http://www.example.com/Amazonsalesarticles/mysefriendlypage.html? [R=301,L]

Jim