I have been using mod_rewrite for a while and love it. However, I am kinda stumped on what to do. Here’s what I want to do:
I have a mobile version of the website and I was going to redirect http://myflashpics.com/user/flashpics to http://myflashpics.com/mobile/user/flashpics
Here’s my code:
RewriteRule user/(.*)/$ /viewer/index.php?profile=$1
RewriteRule user/(.*)$ viewer/index.php?profile=$1
RewriteRule mobile/user/(.*)/$ /mobile/index.php?user=$1
RewriteRule mobile/user/(.*)$ mobile/index.php?user=$1
But when going to the mobile version, it’s showing the desktop version? What’s up with that?
Thanks,
Coulton
Your regular expression for the first two RewriteRules matches your mobile path as well, since
user/(.*)/$just tests to see if the pattern matches at the end of the request path. You should add^to the beginning of your tests so they check that the entire request path matches, as follows:As a side note, you could also save the rewrite engine a bit of trouble and reduce your rule set to two rules. I’d also update your capture expressions, since you probably don’t watch them to include forward slashes at all: