如何让apache RewriteRule正常运行子域?

mik*_*ike 5 apache mod-rewrite

我只是使用以下RewriteCond设置了一个子域:

RewriteCond $1 !^search.php$  
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^/?([^/]+)$ search.php?q=$1 [L,NS] 
Run Code Online (Sandbox Code Playgroud)

我在我的主域上使用相同的重写条件,它完美地运行.但是,当我在子域上设置它时,它只是在转到http://sub.domain.com时输出"index.php"

子域中的每个页面都输出正文中的页面名称而不是处理代码,但搜索页面除外,它似乎正常工作.

我该怎么做才能解决这个问题?

Pow*_*ord 0

这里我想到了几件事:

我有一些建议/评论/陷阱。希望其中之一对您有用:

  1. 确保 search.php 不只是回显其$_GET参数。虽然回想起来这听起来很明显,但它是最容易被忽视的解决方案之一。
  2. RewriteRule在服务器配置文件中指定它与在 .htaccess 中指定它的工作方式略有不同。具体来说,^/服务器配置版本是错误的,因为使用了整个 URL ( http://sub.domain.com/blah)。
  3. 确保首先在主 httpd.conf / apache2.conf 或 .htaccess 中没有为此子域处理其他重写规则。
  4. 确保RewriteEngine On出现在您的配置中,因为它是按 激活的VirtualHost
  5. NS 标志将忽略使用relativeRedirect或relative完成的重定向RewriteRule