【问题标题】:Redirect Rule for hostname in htaccesshtaccess 中主机名的重定向规则
【发布时间】:2016-09-20 02:37:57
【问题描述】:

让,$staging_url = http://xx.xx.xx.xx/

$mobile_url = http://xx.xx.xx.xx/mobile/xxx/testing

我已经在我的htaccess 文件中定义了这个重定向规则:

 RewriteCond "%{HTTP_USER_AGENT}" "(android|blackberry|googlebot-mobile|iemobile|ipad|iphone|ipod|opera mobile|palmos|webos)" [NC]
RewriteRule "/(.*)$" "/mobile/xxx/testing/$1" [L]

当我从手机点击 $staging_url 时,它会重定向到 $mobile_url。但是,当我点击 $staging_url/design?id=23 时。它再次重定向到 $mobile_url ,我希望它重定向到 $mobile_url/design?id=23

提前致谢。我使用变量来定义我的链接,因为堆栈溢出只允许低于 10 名声望的用户使用 2 个链接。 我的 .htaccess 文件:

 RewriteEngine On 
Options FollowSymLinks


RewriteBase /


RewriteCond %{HTTP_USER_AGENT} (facebookexternalhit/[0-9]|Twitterbot|Pinterest|Google.*snippet)
RewriteRule ^(.*)design$ story.php?id=$1 [L,QSA]


RewriteCond %{HTTP_USER_AGENT} "android|blackberry|iphone|ipod|ipad|iemobile" [NC]
RewriteRule ^(.*)$ http://google.com [L]


RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{HTTP_USER_AGENT} !facebookexternalhit/[0-9]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /#/$1 [L]

【问题讨论】:

    标签: php .htaccess redirect


    【解决方案1】:

    mod_rewrite docs 中所述,您可以使用括号获取请求的 URL 的某些部分,并在以后引用它们,例如:

    ^/somepath(.*) /index.php?page=$1
    

    【讨论】:

    • 变化就是问题本身
    • 我假设您的 IP 在这两种情况下都相同?只需将它们排除在外,使用相对路径应该可以正常工作!
    • 进行了更改,仍然无法正常工作。我在这里做错了什么,我的意思是从浏览器打开我的网站,它甚至没有重定向。 ReWriteCond 真的有效吗?
    • 尝试将 .* 重定向到谷歌(或其他),看看是否有任何事情发生。我还注意到您说您有一个htaccess 文件,它应该是.htaccess,但也许这只是问题中的一个错字?如果不行,可以使用 phpinfo() 来检查 mod_rewrite 模块是否开启。
    • 我已经添加了我的 .htaccess 文件。文件名为 .htaccess。 mod_rewrite 已启用。你能看看 .htaccess 文件,如果有任何问题,请更正它。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-24
    • 2018-09-11
    • 2017-08-29
    相关资源
    最近更新 更多