0
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

# To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,L,NC]

## To internally redirect /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME}.php -f [NC]
RewriteRule ^ %{REQUEST_URI}.php [L]

上述内容可以.php从我的所有网址中删除。如果存在,是否可以删除 url 之后的所有参数?例如,重写site.com/index.php?id=24site.com/index

4

1 回答 1

1

?在 %1 之后添加一个:

# To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1? [R,L,NC]
# here ---------^

当重写规则的目标 URI 中有 a 时,除非有标志?,否则该规则不会附加查询字符串。QSA

于 2012-09-11T06:27:51.207 回答