我在root 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
我应该添加什么代码来实现这一目标?
答案 0 :(得分: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]