0

我有一个 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/”之类的请求时,它会重写 category 和 itemId 中的查询字符串,但它也会将我的 css 文件和 Js 文件的基本目录更改为 /foo/bar/设计/css/style.css

第二个问题是我有几个路径,如“login/”、“register/”、“users/”,当我尝试加载相应的文件时,它说:

The requested URL /login/ was not found on this server.

谢谢您的帮助!

4

1 回答 1

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]
于 2013-10-24T19:07:21.010 回答