让我们来看看你重写第一:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/?$ home.php?p=$1 [L,NS]
这是相对改写:替换文本home.php...
不以斜杠。在每个目录上下文中的相对重写(<Directory>
或.htaccess
)需要配置RewriteBase
指令,否则它们会执行错误操作。
其次,你的规则是倒退,如果你想重写home.php
网址为site/index
一个,你必须把home.php
比赛的左侧,右侧的site/index
:
RewriteRule ^home.php?p=(.*) /site/$1
请注意,我有一个绝对重写。这意味着mod_rewrite将通过在其上覆盖http://example.com
来重写重写的URL。一个新的请求现在在内部生成,用于http://example.com/site/<whatever>
。由于我们没有相对重写,因此我们可以不使用RewriteBase
而离开。
至于你的最后一个问题,目前还不清楚为什么当你访问localhost/site/home.php?p=profile.user
你被带到localhost/profile.user
。我怀疑它可能是你的home.php
脚本。您正在尝试使用mod_rewrite
劫持该特定类型的PHP请求并将其发送到其他地方,对吗?
来源
2012-03-12 04:51:17
Kaz
你有什么其他重写规则?你必须发布详细信息。 – ThinkingMonkey 2012-02-20 06:16:13
'RewriteEngine叙述在 的RewriteCond%{REQUEST_FILENAME}!-f 的RewriteCond%{REQUEST_FILENAME}!-d 重写规则^(。*)/?$ home.php?p = 1时$ [L,NS]' – user1219391 2012-02-20 08:56:12
我在这里没有任何错误。你确定你没有错过任何其他细节?并通过编辑问题本身来更新任何细节。 – ThinkingMonkey 2012-02-20 14:36:36