![仅当输入 index.php 时,apache2 重写规则才有效](https://linux22.com/image/584441/%E4%BB%85%E5%BD%93%E8%BE%93%E5%85%A5%20index.php%20%E6%97%B6%EF%BC%8Capache2%20%E9%87%8D%E5%86%99%E8%A7%84%E5%88%99%E6%89%8D%E6%9C%89%E6%95%88.png)
RewriteRule ^index.php/(.*)$ redirect.php?s=$1
适用于
website.com/index.php/something
但不是
website.com/something
有什么方法可以让它工作吗?
RewriteRule ^/(.*)$ redirect.php?s=$1
没有起到作用。
答案1
您可能应该更彻底地澄清您正在寻找什么行为,但这可能接近它。
# Don't redirect for /index.php or /index.php/
RewriteRule ^index\.php/?$ - [L]
# Don't redirect for /redirect.php
RewriteRule ^redirect\.php.* - [L]
# Redirect everything with /index.php/something, keeping everything after index.php/
RewriteRule ^index\.php/(.+)$ redirect.php?s=$1 [L]
# This request didn't start with one of the PHP files, so just dump the whole thing into the query parameter
RewriteRule ^(.*)$ redirect.php?s=$1 [L]