【问题标题】:Apache .hatccess rewrites not working for legacy URLSApache .htaccess 重写不适用于旧版 URL
【发布时间】:2013-07-13 02:31:06
【问题描述】:

我正在尝试在现在使用 ExpressionEngine 作为其 CMS 的网站上重写一些旧版 Joomla URL,但它们无法正常工作。

ExpressionEngine URL 重写,即从 URL 中删除 index.php 工作正常。

这就是我所拥有的:

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteCond %{HTTPS} !=on

# This is the one that's not working
  RewriteRule /index.php?option=com_chronocontact&Itemid=54 /contact/  [R=301,L]

# Force www
  RewriteCond %{HTTP_HOST} !^www\..+$ [NC]
  RewriteCond %{HTTP_HOST} (.+)$ [NC]
  RewriteRule ^(.*)$ http://www.%1/$1 [R=301,L]
# Redirect index.php Requests
  RewriteCond %{THE_REQUEST} ^[^/]*/index\.php [NC]
  RewriteCond %{THE_REQUEST} ^GET
  RewriteRule ^index\.php(.+) $1 [R=301,L]
# Standard ExpressionEngine Rewrite
  RewriteCond %{REQUEST_URI} ^/
  RewriteCond %{QUERY_STRING} ^(gclid=.*)
  RewriteRule ^(.+) /index.php?/ [L,PT]
  RewriteCond $1 !\.(css|js|gif|jpe?g|png) [NC]
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond  $1 !^(assets|css|images|tinymce|js|min|cms|themes|index\.php|admin\.php|favicon\.ico|index\.php|path\.php|php\.ini) [NC]
  RewriteRule ^(.+) /index.php?/ [L]

</IfModule>

谁能发现我做错了什么?

【问题讨论】:

    标签: apache .htaccess mod-rewrite joomla expressionengine


    【解决方案1】:

    第一件事是你在顶部的流浪RewriteCond %{HTTPS} !=on。看起来它属于它下的规则,如:

    RewriteCond %{HTTPS} !=on
    RewriteCond %{HTTP_HOST} !^www\..+$ [NC]
    RewriteCond %{HTTP_HOST} (.+)$ [NC]
    RewriteRule ^(.*)$ http://www.%1/$1 [R=301,L]
    

    就您评论的无效规则而言,? 是正则表达式的保留字符,您的模式实际上表示/index.php 中的第二个p 是“可选的”。此外,您无法匹配重写规则中的查询字符串,您需要使用重写条件并匹配 %{QUERY_STRING} 变量:

    RewriteCond %{QUERY_STRING} ^option=com_chronocontact&Itemid=54$
    RewriteRule ^(index.php)?$ /contact/? [R=301,L]
    

    可能更符合您的要求。

    【讨论】:

    • 谢谢,这与我想要的非常接近,除了页面重定向到 /contact/?option=com_chronocontact&Itemid=54 还有什么方法可以删除查询字符串?
    猜你喜欢
    • 2016-01-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多