首页 > 解决方案 > .htaccess 重写规则不能与 index.php 正确工作?路径

问题描述

嗨,我有以下旧网址

www.domain.de/index.php?leistungen

新的是

www.domain.de/leistungen

我尝试了以下操作RewriteRuile,就像我做了数百万次一样。

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

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

www.domain.de/path/?leistungen=

它路由到根 url

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

提前致谢。

标签: apache.htaccess

解决方案


您可以在站点根目录 .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]

推荐阅读