底部的4条重写规则可以正常工作,但是一旦我添加了第一个规则,就可以从标准页面(例如about.php)中隐藏.php扩展名,那么最后一条规则就停止工作了吗?
使用最后一条规则,我希望URL为domain.com/123,但页面实际上是/offer.php?id=123
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
RewriteRule ^preview/([^/]*)$ /create-preview.php?id=$1 [L]
RewriteRule ^update/([^/]*)$ /update.php?id=$1 [L]
RewriteRule ^delete/([^/]*)$ /delete.php?id=$1 [L]
RewriteRule ^([^/]*)$ /offer.php?id=$1 [L]
像这样:
Options -MultiViews
RewriteEngine On
RewriteRule ^preview/([^/]+)/?$ create-preview.php?id=$1 [L,QSA,NC]
RewriteRule ^(update|delete)/([^/]+)/?$ $1.php?id=$2 [L,QSA,NC]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^(.+?)/?$ $1.php [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/?$ offer.php?id=$1 [L,QSA]
更改为:
MultiViews
(内容协商),因为在两种情况下php文件名与起始路径名相同,即/update
and /delete
。php
在这些规则之后和最后一个前端控制器规则之前放置扩展规则RewriteCond
来跳过物理文件和目录。本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句