TommyDo TommyDo - 1 year ago 71
Apache Configuration Question

Build the rewrite rule with specific path

At first, I sorry to make the simple question but I really didn't know how to build the rule with my special path.

My project path is like:
...and more

With 123456 is the category number, it will be changed automatically but the file structure inside will be same.

Now I have the mobile version:**m_index.html**
...and more

So my question is How can I redirect to m_*.html when access by mobile?


index.html -> m_index.html
001.html -> m_001.html

Any suggest?

Answer Source

You can try this rule in your site root .htaccess:

RewriteEngine On

RewriteCond %{HTTP_ACCEPT} "text\/vnd\.wap\.wml|application\/vnd\.wap\.xhtml\+xml" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "sony|symbian|nokia|samsung|mobile|windows ce|epoc|opera" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "mini|nitro|j2me|midp-|cldc-|netfront|mot|up\.browser|up\.link|audiovox"[NC,OR]
RewriteCond %{HTTP_USER_AGENT} "blackberry|ericsson,|panasonic|philips|sanyo|sharp|sie-"[NC,OR]
RewriteCond %{HTTP_USER_AGENT} "portalmmm|blazer|avantgo|danger|palm|series60|palmsource|pocketpc"[NC,OR]
RewriteCond %{HTTP_USER_AGENT} "smartphone|rover|ipaq|au-mic,|alcatel|ericy|vodafone\/|wap1\.|wap2\.|iPhone|android"[NC]
RewriteRule ^ - [E=MOBILE:1]

RewriteCond %{ENV:MOBILE} =1
RewriteRule ^(cafe/[\w-]+/guide)/?$ /$1/m_index.html [L,NC,R=301]

RewriteCond %{ENV:MOBILE} =1
RewriteRule ^(cafe/[\w-]+/guide)/(?!m_)([\w-]+\.html)$ /$1/m_$2 [L,NC,R=301]