我有一个htaccess文件,我试图重写,但它会导致我多个问题。首先是我的htacess文件:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/ [R=301,L]
RewriteRule ^([a-zA-Z0-9]*)/?$ index.php?category=$1&%{QUERY_STRING}
RewriteRule ^([a-zA-Z0-9]*)/([a-zA-Z0-9]+)/?$ index.php?category=$1&itemId=$2&%{QUERY_STRING}
RewriteRule ^login$ login.php?category=$1&%{QUERY_STRING} [L]
第一个问题是,当我发出类似“mysite / foo / bar /”的请求时,它会重写类别和itemId中的查询字符串,但它也会将我的css文件和Js文件的基本目录更改为/ foo /bar/design/css/style.css
第二个问题是我有一些路径,如“login /”,“register /”,“users /”,当我尝试加载相应的文件时,它说:
The requested URL /login/ was not found on this server.
感谢您的帮助!
答案 0 :(得分:0)
首先像这样更改.htaccess:
RewriteEngine On
## If the request is for a valid directory
RewriteCond %{REQUEST_FILENAME} -d [OR]
## If the request is for a valid file
RewriteCond %{REQUEST_FILENAME} -f [OR]
## don't do anything
RewriteRule ^ - [L]
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/ [R=301,L]
RewriteRule ^([a-zA-Z0-9]*)/?$ index.php?category=$1 [L,QSA]
RewriteRule ^([a-zA-Z0-9]*)/([a-zA-Z0-9]+)/?$ index.php?category=$1&itemId=$2 [L,QSA]
RewriteRule ^login/?$ login.php?category=$1&%{QUERY_STRING} [L,QSA]