views:

127

answers:

1

Hello,

The following url rewrite works fine but it doesn't redirect to the new url.

RewriteRule ^test-(.*)-(.*)\.html$ /test.php?&abc=$1&xyz=$2/ [L]
+2  A: 

If you want to force the browser to be redirected to the URL, you'll need to use the R flag:

RewriteRule ^test-(.*)-(.*)\.html$ /test.php?&abc=$1&xyz=$2/ [R,L]
jmans
I just tried adding [R,L] but nothing happens. It doesn't redirect to the new url.
Does it execute test.php properly but just doesn't redirect?
jmans
jmans
I just tested it again. If I try to access the new url (example:) test-one-two.html it redirects to the dynamic url. But when I try to access the dynamic url it won't redirect to the new url.
@Amy: The main goal of mod_rewrite is to not redirect, the redirection happens only inside the Web Server where the user can't see what's happening. If you want the user to see the redirect happening, you use the R flag, like **[R=301,L]**. I don't know if specifying the HTTP code it needed or optional.
Havenard
@Amy: May you explain your last comment?
Havenard
mod_rewrite rules are one-way. If you want to redirect both ways, you'll have to create two mod-rewrite rules, which could get a little tricky. Why do you want to redirect in both directions? It seems like only one of those URIs would be your preferred URI...
jmans
The HTTP code isn't required, but it is probably more accurate. The default is 302 (MOVED TEMPORARILY).
jmans
jmans
@jpickles, @HavenardMy preferred URI is the .html one. The dynamic url is generated when doing a search. But it doesn't display the new url as I want it to using the rewrite rule. It stays the same. But if I type in the new url manually it redirects to the dynamic url. I would like for it to be the other way around.
Let me know if using the two rules in my earlier comment works for you.
jmans