0

I am trying to build a wordpress site with mobile. I have set the sub-domain in httpd.conf and htaccess.

now i add some custom search in a e:\wp\custom\ folder, another mobile custom search in e:\wp\mobile\custom\. i could open http://localhost/wp/custom/search/hello/1 and http://m.localhost/custom/search/hello/1 correctly.

but if i access http://localhost/wp/custom/search/hello/1 in opera mobile simulator, it will redirect to http://m.localhost/custom/search/hello/1?words=hello&number=1. why the ?words=hello&number=1 hasn't be rewritten?

here is my .htaccess under e:/www/wp/ folder

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /wp/
RewriteRule ^custom/search/(.*)/(\d+)?$ custom/search.php?words=$1&number=$2
# custom folder, with some custom search url rewrite.
RewriteCond %{http_host} ^localhost/wp [NC]
RewriteRule ^(.*)$ http://localhost/wp/$1 [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

#mobile device detective
ewriteEngine on
RewriteBase /wp/
RewriteCond %{QUERY_STRING} (^|&)m=0(&|$)
RewriteRule ^ - [CO=mredir:0:localhost/wp]
RewriteCond %{HTTP:x-wap-profile} !^$ [OR]
RewriteCond %{HTTP:Profile}       !^$ [OR]
RewriteCond %{HTTP_USER_AGENT} "acs|alav|alca|amoi|audi|aste|avan|benq|bird|blac|blaz|brew|cell|cldc|cmd-" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "dang|doco|eric|hipt|inno|ipaq|java|jigs|kddi|keji|leno|lg-c|lg-d|lg-g|lge-" [NC,OR]
RewriteCond %{HTTP_USER_AGENT}  "maui|maxo|midp|mits|mmef|mobi|mot-|moto|mwbp|nec-|newt|noki|opwv" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "palm|pana|pant|pdxg|phil|play|pluc|port|prox|qtek|qwap|sage|sams|sany" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "sch-|sec-|send|seri|sgh-|shar|sie-|siem|smal|smar|sony|sph-|symb|t-mo" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "teli|tim-|tosh|tsm-|upg1|upsi|vk-v|voda|w3cs|wap-|wapa|wapi" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "wapp|wapr|webc|winw|winw|xda|xda-" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "up.browser|up.link|windowssce|iemobile|mini|mmp" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "symbian|midp|wap|phone|pocket|mobile|pda|psp" [NC]
RewriteCond %{HTTP_USER_AGENT} !macintosh [NC]
RewriteCond %{HTTP_HOST}          !^m\.
RewriteCond %{QUERY_STRING} !(^|&)m=0(&|$) 
RewriteCond %{HTTP_COOKIE}        !^.*mredir=0.*$ [NC]
RewriteRule ^(.*)$ http://m.localhost/$1 [R=301,L]

and another htaccess in e:/www/wp/mobile/

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^custom/search/(.*)/(\d+)?$ custom/search.php?words=$1&number=$2
# custom folder, with some custom search url rewrite.
RewriteCond %{http_host} ^m.localhost [NC]
RewriteRule ^(.*)$ http://m.localhost/$1 [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

EDIT I moved mobile device detective before <IfModule mod_rewrite.c>, it seems fix the problem. anyone could help me further to check if there has any other problem? thanks again.

#mobile device detective
ewriteEngine on
RewriteBase /wp/
RewriteCond %{QUERY_STRING} (^|&)m=0(&|$)
RewriteRule ^ - [CO=mredir:0:localhost/wp]
RewriteCond %{HTTP:x-wap-profile} !^$ [OR]
RewriteCond %{HTTP:Profile}       !^$ [OR]
RewriteCond %{HTTP_USER_AGENT} "acs|alav|alca|amoi|audi|aste|avan|benq|bird|blac|blaz|brew|cell|cldc|cmd-" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "dang|doco|eric|hipt|inno|ipaq|java|jigs|kddi|keji|leno|lg-c|lg-d|lg-g|lge-" [NC,OR]
RewriteCond %{HTTP_USER_AGENT}  "maui|maxo|midp|mits|mmef|mobi|mot-|moto|mwbp|nec-|newt|noki|opwv" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "palm|pana|pant|pdxg|phil|play|pluc|port|prox|qtek|qwap|sage|sams|sany" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "sch-|sec-|send|seri|sgh-|shar|sie-|siem|smal|smar|sony|sph-|symb|t-mo" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "teli|tim-|tosh|tsm-|upg1|upsi|vk-v|voda|w3cs|wap-|wapa|wapi" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "wapp|wapr|webc|winw|winw|xda|xda-" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "up.browser|up.link|windowssce|iemobile|mini|mmp" [NC,OR]
RewriteCond %{HTTP_USER_AGENT} "symbian|midp|wap|phone|pocket|mobile|pda|psp" [NC]
RewriteCond %{HTTP_USER_AGENT} !macintosh [NC]
RewriteCond %{HTTP_HOST}          !^m\.
RewriteCond %{QUERY_STRING} !(^|&)m=0(&|$) 
RewriteCond %{HTTP_COOKIE}        !^.*mredir=0.*$ [NC]
RewriteRule ^(.*)$ http://m.localhost/$1 [R=301,L]


<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /wp/
RewriteRule ^custom/search/(.*)/(\d+)?$ custom/search.php?words=$1&number=$2
# custom folder, with some custom search url rewrite.
RewriteCond %{HTTP_HOST} ^localhost/wp [NC]
RewriteRule ^(.*)$ http://localhost/wp/$1 [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
0

You have two blocks of Rewrite* statements in e:/www/wp/.htaccess – the first one has the rewrite for the /wp/custom/search and the fallback to /index.php, the second has the redirect for mobile clients. You need to switch the order of these blocks and send mobile clients to the mobile site before rewriting their URL any further.

Bonus info: the line RewriteCond %{http_host} ^localhost/wp [NC] is useless. First, it should read %{HTTP_HOST}, second, that variable will only ever contain the hostname and no other part of the URL.

  • thanks for your point, i changed %{http_host} to %{HTTP_HOST} and i moved #mobile device detective before <IfModule mod_rewrite.c> in e:/www/wp/.htaccess it seems fix the problem. as you are an expert in url rewrite, do you think is there has any other problem? thanks. – cj333 May 8 '13 at 16:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.