Forum Moderators: phranque

Message Too Old, No Replies

Sorry if I missed the obvious. but.

301 redirect not working

         

Asia_Expat

5:06 am on Mar 10, 2006 (gmt 0)

10+ Year Member



Hello all. Finally I have a reason to post :)
I'm trying to set up the following redirect...

redirect 301 /abc/?Korea_Facts h##p://www.abc.com/korea_facts.php

... but when I upload it to my htaccess file, nothing happens, it simply does not work and the page goes straight to the /index.php. I just can't figure out why. Can anyone see any problems that a web learner like me would miss?

Note, the ##'s were deliberate so a hyperlink doesn't appear..... and I am not the owner of abc.com ;)

jdMorgan

1:46 pm on Mar 10, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Asia_Expat,

Welcome to WebmasterWorld!

If you are trying to redirect a URL with an appended query string, and based on that query string's value, then you'll probably need to use mod_rewrite. In Web-root directory .htaccess:


Options +FollowSymLinks
RewriteEngine on
RewriteCond %{QUERY_STRING} ^Korea_Facts
RewriteRule ^abc/?$ http://www.example.com/ [R=301,L]

Query strings are not considered to be part of a URL; Rather, they are data appended to a URL to be passed to the resource (e.g. script) *at* that URL. Apache therefore handles them separately from the URL.

Note here that the question mark in the RewriteRule pattern is not a literal. It is a regex token that makes the trailing slash on the URL optional.

Depending on your server configuration, you may not need the Options directive. In fact, it may cause problems if it is present but not needed, as well as if it is needed but not present. And if you already have other working rules, then you won't need the RewriteEngine directive, either.

For use in httpd.conf, add a leading slash to the RewriteRule pattern.

Jim

Asia_Expat

5:53 am on Mar 11, 2006 (gmt 0)

10+ Year Member



Thanks :-)
I'll give that a try over the weekend and get back to you.
Thanks again.