【问题标题】:.htaccess Rewrite Rule does not work correctly with index.php?path.htaccess 重写规则不能与 index.php 正确工作?路径
【发布时间】:2019-03-15 04:40:09
【问题描述】:

您好,我有以下旧网址

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


    【解决方案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]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-02-06
      相关资源
      最近更新 更多