.htaccess重写规则不适用于index.php?path

时间:2019-03-14 18:55:01

标签: apache .htaccess

嗨,我有以下旧网址

www.domain.de/index.php?leistungen

而新的是

www.domain.de/leistungen

我尝试了以下RewriteRuile,就像我无数次尝试一样。

RewriteRule ^index.php?leistungen /leistungen/ [L,R=301]

但是在这种情况下,我得到了以下结果:

www.domain.de/path/?leistungen=

它路由到根网址

在这种情况下是什么问题?

谢谢。

1 个答案:

答案 0 :(得分:1)

您可以在网站根.htaccess中使用以下规则:

RewriteEngine On

# external redirect from actual URL to pretty one
RewriteCond %{THE_REQUEST} \s/+(?:index\.php)?\?([^\s&]+) [NC]
RewriteRule ^ /%1? [R=301,L,NE]

# internal forward from pretty URL to actual one
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/?$ index.php?$1 [L,QSA]