Forum Moderators: phranque

Message Too Old, No Replies

301 rewrite Help

301 rewrite Help

         

CainIV

4:55 am on Jun 5, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hello guys, I am looking to find a way to rewrite the following types of urls:

http://www.example.com/treatment/?q=node/110

to:

http://www.example.com/treatment/the-new-file.html

So far I have this in an htaccess located in the treatment folder but cannot get it to work as intended:

RewriteEngine On

RewriteRule ^(*.)q=node/110$ http://www.example.com/treatment/the-new-file.html [R=301,L]

Any help would be appreciated.

[edited by: jdMorgan at 1:08 pm (utc) on June 5, 2007]
[edit reason] example.com [/edit]

benevolent001

4:59 am on Jun 5, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Since you are using drupal you dont have to do anything your self here is what you have to do

1) Enable clean urls in drupal
2) Install pathauto module and in settings add .html extension for [title].html if you want like this

hope this helps

CainIV

5:45 am on Jun 5, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks for the help, but we are moving away from using that system and into using clean hand done html articles, so I will still need help redirecting the old urls to the new cleaner urls done by hand.

jdMorgan

1:08 pm on Jun 5, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Query strings are not visible to RewriteRule, and must be handled by a RewriteCond:

in /treatment/.htaccess:


RewriteCond %{QUERY_STRING} ^q=node/110$
RewriteRule ^$ http://www.example.com/treatment/the-new-file.html? [R=301,L]

Advanced: If you have a lot of pages to redirect, this can be coded in other ways to avoid using two lines per entry, but the resulting code is harder to understand and maintain. Here is a short example:

RewriteCond %{QUERY_STRING}<>the-new-file.html ^q=node/110<>(.+)$ [OR]
RewriteCond %{QUERY_STRING}<>2nd-new-file.html ^q=node/111<>(.+)$ [OR]
RewriteCond %{QUERY_STRING}<>3rd-new-file.html ^q=node/112<>(.+)$
RewriteRule ^$ http://www.example.com/treatment/%1.html? [R=301,L]

Here, the replacement local URL-path is hard-coded into the RewriteCond, and then back-referenced (only if the query matches) in the RewriteRule substitution URL by using %1.

The "<>" characters are arbitrary, serving only to demarcate the query string/replacement URL-path boundary. Note that there is no [OR] flag on the last RewriteCond in the list.

Jim

CainIV

4:49 pm on Jun 5, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Much thanks Jim this works great and your explanation makes alot of sense.