Forum Moderators: phranque

Message Too Old, No Replies

Need Mod Rewrite / Redirect Help

I thought I knew how to do a redirect in .htaccess until now

         

ccity

8:36 pm on Apr 25, 2005 (gmt 0)

10+ Year Member



I should know how to do this, bu for some reason I cannot get it to work.

I am trying to permanently redirect this:

[mysite.com...]

...to:

[mysite.com...]

I tried this:

Redirect 301 ^/headline.cfm http:/mysite.com/

Now, when I go to:

[mysite.com...]

...it redirects me to this:

[mysite.com...]

I do not want the query string on the end. I just want it to go to my homepage.

I tried this:

Redirect 301 ^/headline.cfm?id=57 http:/mysite.com/

... but that didn't even redirect me.

Can anyone help?

jd01

9:19 pm on Apr 25, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I can't help you with Redirect, tried that once... not my thing. (it is a mod_alias directive)

If you are using mod_rewrite, you will need to use a condition to account for a specific query string:

RewriteCond %{QUERY_STRING} ^id=57$
RewriteRule ^headline\.cfm$ /index.html? [R=301,L]

or

RewriteCond %{THE_REQUEST} ^headline\.cfm\?id=57$
RewriteRule ^headline\.cfm$ /index.html? [R=301,L]

You may or may not need the trailing '?' on the rule, it actually appends a blank query string, so nothing is automatically transferred from the original request.

Hope this helps.

Justin

jdMorgan

10:17 pm on Apr 25, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



RewriteCond %{THE_REQUEST} ^headline\.cfm\?id=57$
RewriteRule ^headline\.cfm$ /index.html? [R=301,L]

The value tested as THE_REQUEST is the entire request line sent by the client. It's going to be something like:

GET /headline.cfm?id=57 HTTP/1.1

Therefore, the RewriteCond pattern above should not be start-anchored or end-anchored, or it should allow for the HTTP METHOD before the URL-path. That is, either

RewriteCond %{THE_REQUEST} /headline\.cfm\?id=57

-or-

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /headline\.cfm\?id=57\ HTTP/

The trailing "?" on the Rule *is* required -- in order to remove the query string as desired.

You may also need to preced the code with:


Options +FollowSymLinks
RewriteEngine on

Jim

ccity

12:47 am on Apr 26, 2005 (gmt 0)

10+ Year Member



Thank you!