【发布时间】:2016-07-27 07:15:10
【问题描述】:
好吧,我正在使用 .htaccess 规则来编辑我的网站 url 结构。现在,我有以下网址:
http://localhost/aponit/dev/zones
此 url 用于 zone.php 页面以编辑表单数据。单击编辑链接后,它将转到此链接:
http://localhost/aponit/dev/zones/update/55
此链接在update.php 页面上打开。
现在,如果我从这个网址中删除以下部分
/55 or date/55
然后它会向我显示带有相应错误页面的错误消息。很好。
但如果我从 url 中删除 update/55,那么 url 看起来像这样:
http://localhost/aponit/dev/zones/ (note the forward slash at the end)
然后它正在调用 zone.php 页面并且样式表已损坏
但我想显示一个错误页面,例如:not-found.php 页面。我怎样才能使用 .htaccess 做到这一点?
我的 .htaccess 规则:
Options -MultiViews
ErrorDocument 404 http://localhost/aponit/dev/not-found.php
ErrorDocument 500 http://localhost/aponit/dev/404.php
RewriteEngine on
RewriteRule ^(?:zones/)?update/(\w+)/?$ update.php?z=$1 [L,QSA,NC]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+?)/?$ $1.php [L]
【问题讨论】:
标签: apache .htaccess url mod-rewrite