如果任何通配符作为子域条目访问浏览器,我希望我的 .htaccess 文件重定向到某个页面。即我想要
sam.xyz.com
重定向至
sam.xyz.com/view.php?id=sam
我正在使用以下重写规则进行重定向。
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www.xyz.com [NC]
RewriteCond %{HTTP_HOST} ^([^.]+).xyz.com
RewriteRule ^(.*)$ /view.php?id=%1 [L,R]
我面临的问题是它不会转移到保留查询字符串的新域,而是会生成无限循环
sam.xyz.com
重定向至
http://sam.xyz.com/view.php?id=sam
但不会在没有无限循环的情况下移动到上面的 url。 请帮助我。 提前致谢,
最佳答案
您应该添加重定向条件以防止重定向循环:
RewriteCond %{REQUEST_URI} !^/view\.php
整个代码是:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www.xyz.com [NC]
RewriteCond %{HTTP_HOST} ^([^.]+).xyz.com
RewriteCond %{REQUEST_URI} !^/view\.php
RewriteRule ^(.*)$ /view.php?id=%1 [L,R]
关于apache - .htaccess重写规则导致无限循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17351608/