1

我在根 htaccess 中使用它

RewriteEngine on
Options +FollowSymLinks

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l 
RewriteRule .* index.php?p=%{REQUEST_URI} [L]

这会成功重写http://example.com/notexistsfolder

但我也想将http://example.com/user/notexistsfolder重定向到http://example.com/notexistsfolder

我应该添加什么代码来实现这一点?

4

1 回答 1

0

这是您在目录.htaccess下需要的代码:DOCUMENT_ROOT

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

## 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]
## If the request is for a valid link
RewriteCond %{REQUEST_FILENAME} -l
## don't do anything
RewriteRule ^ - [L]

RewriteRule ^user/(.*)$ $1 [L,NC]

RewriteRule (?!^user/)^(.*)$ index.php?p=$1 [L,NC,QSA]
于 2012-06-16T17:38:45.000 回答