我需要帮助重写.htaccess文件中的重写 . 所以这就是我现在所拥有的这个有效但当我尝试添加一个新的RewriteRule时没有任何反应 . 我想要重写的网址是index.php?page = $ 1
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ profile.php?username=$1
所以当我这样做时:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ profile.php?username=$1
RewriteRule ^(.*)$ index.php?page=$1
当我这样做时页面没有任何CSS:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ profile.php?username=$1
RewriteRule ^(.*_)$ index.php?page=$1
页面有css,但我仍然得到index.php?page = pagetitle . 但是 Profiles 页面确实给了我/用户名 .
2 回答
您要求服务器将每个URL重定向到两个不同的页面,它无法正常工作,服务器无法猜测要加载哪个页面 .
您需要的是/ profile / username规则或/ page / pagetitle规则 . IE之类的东西:
您的重写规则基于正则表达式,因此需要尽可能具体,以便服务器可以确切地确定要使用的URL - 例如,如何判断http://example.com/something是页面还是配置文件?在您的网址上使用"user","profile"等前缀意味着http://example.com/profile/something可以重定向为用户名,其他所有内容都具有默认重定向 . 要实现此目的,您需要首先使用更具体的模式匹配(用户),并使用
[L]
指令指示不应处理以下规则 . 我通常使用URL的负字符类来匹配除正斜杠之外的任何内容 -[^/]*
.在http://htaccess.madewithlove.be/进行测试(请注意,测试不支持
%{REQUEST_FILENAME}
和%{REQUEST_FILENAME}
) .Profile
Page