Ben
Ben

Reputation: 885

Change URL with mod_rewrite

I've added a mobile version which redirects automatically with MobileDetect.php.

After redirect the URL is: /index.html?mpage=home. For example, when the Desktop version URL is /medical-studies, the mobile is /index.html?mpage=medical-studies.

I want to use mod_rewrite or other mod if possible that the mobile version will show the same desktop URL;

I mean change

/index.html?mpage=X

to

/X

Upvotes: 0

Views: 206

Answers (1)

yasu
yasu

Reputation: 1364

Try this:

RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} iPhone [OR]
RewriteCond %{HTTP_USER_AGENT} Android [OR]
RewriteCond %{HTTP_USER_AGENT} Blah...
RewriteRule ^(.*)$ index.html?mpage=$1 [L]

If User-Agent matches some of mobile agents, mod_rewrite internally redirects the access to index.html with original path added. (URL shown in User-Agents does not changed.)

Note

  • RewriteCond should be replaced with proper conditions.
  • In server-side programs, you may have to refer REDIRECT_QUERY_STRING instead of QUERY_STRING.

Upvotes: 1

Related Questions