.htaccess mod rewrite做了一些奇怪的事情
.htaccess mod rewrite做了一些奇怪的事情,.htaccess,mod-rewrite,.htaccess,Mod Rewrite,http://localhost/clean_urls/user/whtffgh将罚款重定向到此http://localhost/clean_urls/user/whtffgh/(我放在那里的几乎任何东西都有效) http://localhost/clean_urls/user/cohen但是,会重定向到此 http://localhost/clean/我不知道为什么。它应该只添加一个/ 这是我的密码 <ifModule mod_rewrite.c> RewriteEngin
http://localhost/clean_urls/user/whtffgh
将罚款重定向到此http://localhost/clean_urls/user/whtffgh/
(我放在那里的几乎任何东西都有效)
http://localhost/clean_urls/user/cohen
但是,会重定向到此
http://localhost/clean/
我不知道为什么。它应该只添加一个/
这是我的密码
<ifModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ /clean_urls/user/$1/ [L,R=301]
RewriteBase /clean_urls/user/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-zA-Z0-9]+)/$ index.php?user=$1
</ifModule>
重新启动发动机
重写基/
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_URI}!(.*)/$
重写规则^(.*)$/clean_URL/user/$1/[L,R=301]
重写基本/清除URL/用户/
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
重写规则^([a-zA-Z0-9]+)/$index.php?用户=$1
更新:
除此之外,当我将cohen作为用户名时,代码也起作用。.htaccess文件的第二部分是使user/index.php?user=username
看起来像user/username
,因此它只是一个$\u GET变量,在url中看起来很好,并且对SEO很友好(显然)
我只是在学习这些东西,并制作一个网络应用程序来尝试它,所以我不确定它会去哪里,但我确实认为我最终需要另一个变量
http://localhost/clean\u url/user/fred/someverb
您误解了RewriteBase指令的用途。它帮助“每个目录”上下文中的重写引擎将相对URI转换为正确的等效文件名
每个.htaccess
文件只能有一个RewriteBase指令。默认情况下,重写引擎将使用路径上最低的.htaccess
文件,并设置RewriteEngine on
指令
因此,在DOCroot(即“GET/xxx”映射到的目录)中,这应该是
RewriteBase /
如果您的.htaccess
文件位于DOCroot/clean\u url/user
中,则它应该具有
RewriteBase /clean_urls/user/
您想如何解码形式为http://localhost/fred
的URI,还是只想处理形式为http://localhost/clean\u url/user/fred/
的URI。关于http://localhost/clean\u url/user/fred/someverb
的URI呢
让我知道你把你的位置
.htaccess
,然后我可以给你正确的内容。我在问题中添加了一个更新,澄清了问题的症结所在。但是你是否理解我的观点,并根据我的观点采取行动。htaccess?按照我的建议拆分它们。我现在明白你的意思了。我将它们拆分,看看是否有问题Works。