【发布时间】:2010-10-12 13:00:39
【问题描述】:
我有一个域,我们称之为 newsite.com,它停在 maindomain.com。我使用 mod-rewrite 将所有对 newsite.com 的请求定向到 maindomain.com 上的子目录。在 newsite.com 上,我安装了 CodeIgniter。这意味着网址看起来像这样:
newsite.com/products/shoes/
上面的工作正常。
但是,如果我为这样的页面设置控制器:
newsite.com/about/ 或 newsite.com/about/faqs/
我得到一个 404,我认为这是因为它正在寻找确实存在但在 newsite.com 上不存在的页面 maindomain.com/about.php。
我的问题是....如何防止像 newsite.com/about/ 这样的网址指向 newsite.com/about.php ?这与许多人试图做的相反(他们倾向于允许缺少文件扩展名)。
我想知道是否是 apache 或 PHP 设置导致它首先查找文件(如果文件存在而目录不存在)?还是我需要添加更多的 mod-rewrite 规则?
非常感谢!
编辑 - 这是我目前的 .htaccess 文件。它位于 maindomain.com 共享主机帐户的 Web 根目录中。
# Redirect various urls to subfolders of the format: /site-thename/
RewriteEngine On
# Remove the www for NewSite.
RewriteCond %{HTTP_HOST} ^www.newsite.com$ [NC]
RewriteRule ^(.*)$ http://newsite.com/$1 [R=301,L]
# Handle pages and directories that should not go through CodeIgniter.
RewriteCond %{HTTP_HOST} ^(www\.)?newsite\.com
RewriteCond %{REQUEST_URI} !^/site-newsite/
RewriteCond %{REQUEST_URI} ^/demo/ [OR]
RewriteCond %{REQUEST_URI} ^/robots\.txt [OR]
RewriteCond %{REQUEST_URI} ^/emailform\.php [OR]
RewriteCond %{REQUEST_URI} ^/assets/ [OR]
RewriteCond %{REQUEST_URI} ^/index\.php
Rewriterule ^(.*)$ /site-newsite/$1 [L]
# Handle CodeIgniter URLs.
RewriteCond %{HTTP_HOST} ^(www\.)?newsite\.com
RewriteCond %{REQUEST_URI} !^/site-newsite/
Rewriterule ^(.*)$ /site-newsite/index.php?/$1 [L]
【问题讨论】:
-
您可以从新网站发布您的 .htaccess 内容吗?
-
好的。添加了 htaccess 文件内容。
-
当我在 404 页面上转储 phpinfo 时,我可以看到:_SERVER["QUERY_STRING"] = /about.php/ 所以它以某种方式将目录更改为 php 页面。
标签: php apache mod-rewrite codeigniter