htaccess 子域名重定向问题

htaccess 子域名重定向问题

httpd.conf我正在尝试使用移动设备构建一个 wordpress 网站。我已在和中设置了子域名htaccess

现在我在e:\wp\custom\文件夹中添加了一些自定义搜索,其中还有另一个移动自定义搜索e:\wp\mobile\custom\。我可以http://localhost/wp/custom/search/hello/1正确打开http://m.localhost/custom/search/hello/1

但是如果我http://localhost/wp/custom/search/hello/1在 opera 移动模拟器中访问,它将重定向到http://m.localhost/custom/search/hello/1?words=hello&number=1。为什么?words=hello&number=1还没有重写?

这是我的e:/www/wp/文件夹下的 .htaccess

<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]

和另一个 htaccesse:/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>

编辑mobile device detective之前搬过家<IfModule mod_rewrite.c>,似乎问题已经解决了。有人能帮我进一步检查是否还有其他问题吗?再次感谢。

#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>

答案1

您有两个 Rewrite* 语句块e:/www/wp/.htaccess– 第一个块包含 的重写/wp/custom/search和回退/index.php,第二个块包含移动客户端的重定向。您需要切换这些块的顺序,并在进一步重写其 URL 之前将移动客户端发送到移动网站。

附加信息:此行RewriteCond %{http_host} ^localhost/wp [NC]毫无用处。首先,它应该读作%{HTTP_HOST};其次,该变量将只包含主机名,而不包含 URL 的其他部分。

相关内容