apache - .htaccess重写规则导致无限循环

标签 apache .htaccess redirect mod-rewrite url-rewriting

如果任何通配符作为子域条目访问浏览器,我希望我的 .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/

相关文章:

php - 如何使 apache 进程 TCP 连接?

python - Apache:重定向到 WSGI 脚本错误?

java - Nutch 1.6 查找重定向的原始 url

apache - 我在 hadooplibs 文件夹中找不到 Apache Oozie Hadoop Libs tar.gz 文件

html - .htaccess 重写单页 anchor 规则(seo 友好)

.htaccess - 使用 .htaccess 为多个参数重写 URL

apache - htaccess 通过查询字符串阻止请求

python - 为什么 Flask 重定向到 "GET/? HTTP/1.1"

javascript - 如何使用重定向 URL 中的对象结果进行重定向?

用于 Rails 应用程序 Gitlab 的 Apache2 ProxyPass