重写规则不允许我访问我的域的index.php

时间:2011-11-20 01:08:08

标签: php .htaccess

在我的页面中,当我写url domain.com/abc时,它使用htaccess RewriteRule(在下面发布)并打开company-profile.php页面,显示ABC配置文件。 ABC就是一个例子。它可能是任何东西

然而,即使我有一个domain.com/index.php文件,当我只写domain.com并点击回车时,它会带我到 company-profile.php 页面。显示 index.php 文件

我的问题是如何解决这个问题?

RewriteEngine On
RewriteRule ^([a-z0-9]+)?$ /domain.com/company-profile.php?cid=$1 [NC,L]

3 个答案:

答案 0 :(得分:0)

RewriteRule的第一部分匹配任何,它们是字母和数字的组合,并将其传递给您的/domain.com/profile/company-profile.php脚本。你需要在RewriteRule上更加具体,即:

RewriteEngine On
RewriteRule ^/profile/([a-z0-9]+)?$ /domain.com/profile/company-profile.php?cid=$1 [NC,L]

上述内容仅匹配以/profile/开头的请求,因此例如/profile/martinbean将匹配。

答案 1 :(得分:0)

这样的事可能吗?

RewriteCond %{REQUEST_URI} !^/$
RewriteCond %{REQUEST_URI} !^/index.(php|html?)
RewriteRule ^(.*)$ profile/company-profile.php?cid=$1 [NC,L]

答案 2 :(得分:0)

apache是​​您的Web服务器吗?如果答案是肯定的,您应该先检查加载的apache模块,看看是否加载了重写模块。如果没有,那么尝试添加这一行:

LoadModule rewrite_module /usr/lib/apache2/modules/mod_rewrite.so

到你的apache配置文件。然后尝试重新启动Web服务器以检查reirte规则是否有效。

相关问题