仅当输入 index.php 时,apache2 重写规则才有效

仅当输入 index.php 时,apache2 重写规则才有效
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]

相关内容