Forum Moderators: phranque

Message Too Old, No Replies

.htaccess Url Redirect Headache

Looking for help that can explain how to redirect a url using varibles

         

Daleeburg

8:45 pm on May 18, 2007 (gmt 0)

10+ Year Member



I am currently working on a site that will act as a backup to another one of my sites. I would like to have it so that if the user goes to www.mysite.com/zzzz/yyyy (no extension)they end up at www.mysite.com/cached/zzzz/yyyy.html I have been told this can be done through htaccess, but since the site is highly dynamic I need to find a way to do this with variables.

I have been looking around and this is what i have made, but it doesnt work

RewriteEngine On
RewriteRule ^(.*)/(.*)$ /cache/$1/$2.html [nc]

Any help would be greatly appreciated.
(also is there a way so the redirect only happens if the url is www.mysite.com/zzzz/yyyy and not like www.mysite.com/index.php)

Edit: apparently this forum doesnt like seeing 3 x's in a row. srry

[edited by: Daleeburg at 8:46 pm (utc) on May 18, 2007]

g1smd

8:57 pm on May 18, 2007 (gmt 0)

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



You'll need a RewriteCond line to specify which URLs the RewriteRule will work for.

jdMorgan

9:31 pm on May 18, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Your pattern is too ambiguous, and the code does not detect "no extension" or contain any provisions to prevent an "infinite" rewriting loop:

RewriteEngine on
# Rewrite /zzzz/yyyy to /cache/zzzz/yyyy.html
RewriteRule ^([^/]+)/([^/.]+)$ /cache/$1/$2.html [NC,L]

Note that the pattern for the last path-part specifies that no additional slashes or periods may occur in that part if the rule is to be invoked.

> (also is there a way so the redirect only happens if the url is www.mysite.com/zzzz/yyyy and not like www.mysite.com/index.php)

This is already taken care of, because "index.php" has an extension, so the rule won't apply. The same thing keeps the rule from looping.

Jim

Daleeburg

10:30 pm on May 18, 2007 (gmt 0)

10+ Year Member



You guys are amazing, i spent 6 hours looking for how to do this.

Thank you so much
~D

g1smd

8:32 pm on May 20, 2007 (gmt 0)

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



Cool! I learnt something new there too.