Forum Moderators: phranque

Message Too Old, No Replies

Simple .htaccess redirect

         

Enigma5

6:31 pm on May 11, 2011 (gmt 0)

10+ Year Member



I am trying to redirect specific pages and I can't seem to get the snytax correct for the .htaccess file. Here is what I want to do...

http://www.example.org/old/index.php?x=reviews&id=1064

Redirect to

http://www.example.org/griffin-tuneflex-aux-with-smartclick-for-iphone-review/

any help would be appreciated!

aishalal

7:35 pm on May 11, 2011 (gmt 0)

10+ Year Member



Options +FollowSymlinks
RewriteEngine on
rewritecond %{http_host} ^www.example.org/old/index.php?x=reviews&id=1064 [nc]
rewriterule ^(.*)$ http://www.example.org/griffin-tuneflex-aux-with-smartclick-for-iphone-review/ $1 [r=301,nc]

just copy and past this code in notepad and upload it.
your site ll redirect to new one

Thank you

Enigma5

7:49 pm on May 11, 2011 (gmt 0)

10+ Year Member



quick question, what does the "nc" do?

I was told before the rewrites should end like this [R=301,L]

lucy24

8:53 pm on May 11, 2011 (gmt 0)

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



NC = no case = it doesn't matter if the original request said

old
or
Old
or
OLD

301 = "yo! google! this page has moved forever, so stop indexing it"

L = stop here and don't apply any further rewrites if you've done this one

Enigma5

9:07 pm on May 11, 2011 (gmt 0)

10+ Year Member



Ok so I changed my .htaccess and now on every page of the site a get a 500 server error, are you sure the syntax is correct?

g1smd

1:05 am on May 12, 2011 (gmt 0)

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



HTTP_HOST is the wrong server variable to test. In any case it holds only the hostname. It does not hold the path nor the query string.

You will instead need a RewriteCond looking at THE_REQUEST here.

I hae posted code for this type of redirect here in this forum within the last 72 hours. It's a question that is asked several times per week.

lucy24

4:13 am on May 12, 2011 (gmt 0)

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



Urk, sorry, I just realized you were asking about the second "nc". You don't need that one at all, since the rule doesn't contain any explicit text.

Irrelevant suggestion: If you haven't already got one, make a custom 500 page to go with your 404 and 403. Any visitors who arrive while you're sorting out the htaccess syntax will thank you ;)