Reputation: 9732
I've been working on the iPhone version of an already existing application.
We use some rewrite rules for better SEO and to make it easier for visitors. eg. http://www.site.com/index.php?job=4ef187d6e66b7 is rewritten as http://www.site.com/jobs/4ef187d6e66b7
We also use a rule to redirect all iPhone users to our mobile site, as following:
RewriteCond %{HTTP_USER_AGENT} iPhone
RewriteCond %{REQUEST_URI} !^/m/
RewriteRule .* /m/ [R]
The mobile site is just located at www.site.com/m/
But when I head over to http://www.site.com/jobs/4ef187d6e66b7, I'm getting redirected to http://www.site.com/m/?job=4ef187d6e66b7, while that should be http://www.site.com/m/jobs/4ef187d6e66b7
Is there a way to redirect people and still keep some of the existing rules? I also tried adding this rule, but that didn't work
RewriteRule ^m/jobs/([^/]+) m/index.php?job=$1 [NC]
This is the full .htaccess
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^jobs/([^/]+) index.php?job=$1 [NC]
RewriteCond %{HTTP_USER_AGENT} iPhone
RewriteCond %{REQUEST_URI} !^/m/
RewriteRule .* /m/ [R]
Upvotes: 1
Views: 229
Reputation: 12198
You should put the iPhone redirect first, and then mark it 'last'. That way, the mobile redirect will have priority over the other redirects.
RewriteCond %{HTTP_USER_AGENT} iPhone
RewriteCond %{REQUEST_URI} !^/m/
RewriteRule (.*) /m/$1 [R,L]
RewriteRule ^(m/|)jobs/([^/]+) index.php?job=$2 [NC]
Also be sure that you include the original path in the redirect (as shown on the third line).
The last rewrite rule will match /m/jobs/xxx
as well as /jobs/xxx
.
Upvotes: 1