我已经写了codeS低于内的.htaccess文件。
I've written the codes below inside a .htaccess file.
RewriteEngine On
Options +FollowSymLinks
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/.]+)/([^/.]+)/?$ index.php?p=$1&id=$2 [NC,QSA,L]
RewriteRule ^([^/.]+)/?$ index.php?p=$1 [NC,QSA,L]
我已经做了一个控制面板,我的网站里面的管理目录的管理员了。问题是,当我想进入到这个地址控制面板 www.site.com/admin
,这并不表明我真正想要的。在此之后,网址更改为 www.site.com/admin/?p=admin
。
这是什么问题?
I have made a control panel for administrator of my website inside admin directory too. The problem is that when I want to enter to control panel from this address www.site.com/admin
, it does not show what I really want. After that, URL changes to www.site.com/admin/?p=admin
.
What is the problem ?
的条件应用只以下规则。 即使是现有的目录或文件,你的第二个规则进行评估。
Conditions are applied on following rule only. Your second rule is evaluated even if it is an existing directory or file.
如果您2规则必须遵守两个条件,你有2个可能性。
If your 2 rules must respect both conditions, you have 2 possibilities.
复制您的条件:
RewriteEngine On
Options +FollowSymLinks
# this rule is evaluated if not a directory AND not a file
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/.]+)/([^/.]+)/?$ index.php?p=$1&id=$2 [NC,QSA,L]
# this rule is evaluated if not a directory AND not a file
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/.]+)/?$ index.php?p=$1 [NC,QSA,L]
或者模拟的if / else
做什么,如果它是一个目录/文件情况
Or simulate if/else
condition by doing nothing if it's a directory/file
RewriteEngine On
Options +FollowSymLinks
# if file or directory, leave (do nothing)
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule . - [L]
# if we reach here, means it's not a file or directory. So rules can be evaluated
RewriteRule ^([^/.]+)/([^/.]+)/?$ index.php?p=$1&id=$2 [NC,QSA,L]
RewriteRule ^([^/.]+)/?$ index.php?p=$1 [NC,QSA,L]
此外,这是不那么重要,但你不必逃避
时到方括号:([^ /.]+)
可([^ /] +)