views:

18

answers:

2

In my htaccess file, I have the following two rules. I would like to make the second one occur on the condition that the first one doesn't match. Currently, they both get run. Is there any way around the collision?

redirect 301 /lorem/ipsum-keyword.html /lorem/dolorem-keyword.html
RewriteRule (.*)-keyword.html$  /dir/file.php?param=$1

Thanks in advance.

A: 

You might use a rewrite rule for the 301 and add the L flag, so it will ignore the following rules.

I can't test it, but this should work:

RewriteRule /lorem/ipsum-keyword.html$  /lorem/dolorem-keyword.html [R=301,L]
RewriteRule (.*)-keyword.html$  /dir/file.php?param=$1
Kau-Boy
The first rule isn't catching at all... even when i remove the second
Matrym
Then your "Redirect 301" wouldn't work either. You might have to make the rule relative and not absolute. AS I don"t know your file system strucutre I can't tell you what is wrong. The sytax of the rule should be OK.
Kau-Boy
+1  A: 

Use mod_rewrite for both and use the L option to ensure that no further rewriting occurs. Something like this:

RewriteRule ^lorem/ipsum-keyword.html$ http://yourdomain.com/lorem/dolorem-keyword.html [R=301,L]
RewriteRule (.*)-keyword.html$  /dir/file.php?param=$1
mwittrock
Hrm, it's not working for me :(
Matrym
You need to adjust the first rule to match your exact document. I'll update.
mwittrock
That ^ was critical too. Thanks!
Matrym