I just don’t get it:
Options +FollowSymlinks -MultiViews
RewriteEngine on
RewriteBase /
RewriteRule ^([a-z]+\-[0-9]+)/?$ $1/home/ [R]
RewriteRule ^[a-z]+\-([0-9]+)/(home|alone)/?$ /$2.php?id=$1 [L]
RewriteRule ^.*$ http://www.anotherdomain.com/ [R=301]
why is the last rule (and by last I mean the redirection to anotherdomain.com) always processed?.
I need something like this:
http://mydomain.com/some-344 ---> http://mydomain.com/some-344/home/
http://mydomain.com/some-344/ ---> http://mydomain.com/some-344/home/
http://mydomain.com/some-344/home/ ---> home.php?id=344
http://mydomain.com/some-344/alone/ ---> alone.php?id=344
http://mydomain.com/anythingelse... --> http://www.anotherdomain.com/
thanks!
The last rule is always processed, because
^.*$will always match. While you’ve specified theLflag on the second rule, it probably doesn’t work quite like you expect.It’s also a good idea to make sure when redirecting to a local path, you include a leading slash, and when redirecting in general, you specify the
Lflag so the redirect happens immediately. Currently, it all works out OK, but if you look at the processing going on under the hood, it’s doing things a little more messily than necessary.As far as your actual issue goes, conditioning the catch-all redirect based on the original request to the server should get you what you wanted: