【问题标题】:htaccess redirect from domain.com/index.php?page=about to domain.com/abouthtaccess 从 domain.com/index.php?page=about 重定向到 domain.com/about
【发布时间】:2012-10-07 16:48:48
【问题描述】:

我升级了一个旧网站,并希望将所有旧页面重定向到新页面。旧网站使用索引页面和查询字符串来提供相关内容。

这是新的 htaccess 文件。有问题的问题是让重定向工作。另外,如果您可以简化此文件:

Options +FollowSymLinks
Options +Indexes
RewriteEngine on
RewriteBase /

RewriteCond %{HTTP_HOST} ^www.domain.co.uk$ [NC]
RewriteRule ^(.*)$ http://domain.co.uk/$1 [R=301,L]

#if its not a directory
RewriteCond %{REQUEST_FILENAME} !-d
#and it has a trailing slash then redirect to URL without slash
RewriteRule ^(.+)/$ /$1 [L,R=301]

#this removes php extention
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L] 

# stops you accessing url with.php
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /([^.?\ ]+)\.php
RewriteRule ^([^.]+)\.php(/.+)?$ /$1%{PATH_INFO} [R=301]

RewriteRule ^news/([^/]*)/([^/]*)$ /news?id=$1&title=$2 [L]

Redirect 301 index?page=about http://domain.co.uk/about

ErrorDocument 404 http://domain.co.uk/404

【问题讨论】:

    标签: .htaccess query-string


    【解决方案1】:

    将 domain.com/index.php?page=about 重定向到 domain.com/about 的适当规则如下

    RewriteRule ^index\.php$ %{QUERY_STRING} [C]
    RewriteRule page=(.*) /$1? [R=301,L]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-02-22
      • 1970-01-01
      • 2013-02-14
      • 1970-01-01
      • 1970-01-01
      • 2016-07-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多