【发布时间】:2023-01-10 14:33:12
【问题描述】:
我有一个包含以下行的 .htaccess 文件
# ErrorDocument 404 /error/404.php
Options All -Indexes -MultiViews
RewriteEngine On
# Allow urls to not include the .php extension
RewriteCond %{REQUEST_URI}/$1.php -f [NC]
RewriteRule ^(.+?)/?$ $1.php [L]
# Silent Redirect from any url ending with mcc-* to show.php?id=mcc-*
# This is the portion that isn't working
RewriteCond %{REQUEST_URI} (mcc-[\d]+)\.php$
RewriteCond %{REQUEST_URI}/$1.php -f [NC]
RewriteRule show.php?id=$1 [L]
我试图找到以模式 (mcc-[\d]+) 结尾的任何 url 并将其重定向到 show.php?id=%pattern%,但是尝试访问与此模式匹配的页面只会返回 404 错误,因为没有文件 mcc-*。
【问题讨论】:
-
所以你在浏览器上点击
http://localhost:80/mcc-blablabla-etc这样的URL,你想把它重定向到http://localhost:80/show.php?id=mcc-blablabla-etc?请确认一次。
标签: apache .htaccess mod-rewrite