【问题标题】:.htaccess if request url diffrent from some string than.htaccess 如果请求 url 与某个字符串不同
【发布时间】:2013-12-20 15:12:44
【问题描述】:

我有一个关于 htaccess 重写条件的小问题。 我想在我的 htaccess 中做的是:

当有人从不同于“example.com”的 url 访问我的项目以重定向到特定控制器时,例如 app_user.php

我需要这个条件重定向的语法。

感谢您的宝贵时间

【问题讨论】:

  • 这个不清楚:accesses my project from a url different from "example.com"如何访问?什么是“我的项目”?这可能是引荐来源问题,或者是多个服务器别名指向同一服务器的问题...
  • 我得到了答案,但是 ill make the question more clear just for future references. I have more than 1 domains pointing to my web project. I want all of the domains which arent "example.com" 在访问要重定向到特定前端控制器的项目时。

标签: php regex apache .htaccess mod-rewrite


【解决方案1】:

在您的 DOCUMENT_ROOT/.htaccess 文件中尝试此代码:

RewriteEngine On

RewriteCond %{HTTP_HOST} !^example\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/app_user.php
RewriteRule ^ /app_user.php [L]

【讨论】:

  • 对不起,如果我没有正确解释它。当一些人从不同的 url 访问我的项目时,我需要:“example.com”。如果url后面的路径不同,您给出的示例可以解决问题。
  • 完美运行。非常感谢。
猜你喜欢
  • 2011-03-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-05-20
  • 1970-01-01
  • 2021-05-10
  • 1970-01-01
  • 2011-01-22
相关资源
最近更新 更多