【问题标题】:Codeigniter URLs: 301 redirects always adding a ? (question mark) or extra directoriesCodeigniter URL:301 重定向总是添加一个? (问号)或额外目录
【发布时间】:2015-12-07 16:37:04
【问题描述】:

在 codeignitor .htaccess 中,我正在尝试 301 将旧的/未使用的 url 重定向到新的目录/页面 - 但无论我做什么,它都会添加一个问号作为 adirecty...如果我从.htaccess ....它仍然在url加上旧路径中添加问号...

我在下面包含了我的代码:

RewriteBase /

# Remove trailing slashes
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ $1/ [R=301,L]

# Actually 301 direct all index.php requests
RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,L]

# this gets rid of index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/$1 [L]

Redirect 301 /old-page /newdir/new-page/?

如果我要进入:

/old-page > 会去 >>> /newdir/new-page/?/

或者如果我从 e.htaccess 中去掉问号,那将是......

/newdir/new-page/?/old-page

当我想要的时候......

/newdir/new-page

希望有人能帮忙

【问题讨论】:

    标签: .htaccess codeigniter redirect


    【解决方案1】:

    不要将mod_aliasRedirect 指令与mod_alias (RewriteEngine) 规则混用。

    像这样使用它:

    RewriteEngine On
    RewriteBase /
    
    RewriteRule ^old-page/?$ /newdir/new-page/? [L,NC,R=301]
    
    # Remove trailing slashes
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_URI} !(.*)/$
    RewriteRule ^(.*)$ $1/ [R=301,L]
    
    # Actually 301 direct all index.php requests
    RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,L]
    
    # this gets rid of index.php
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?/$1 [L]
    

    【讨论】:

      猜你喜欢
      • 2012-10-30
      • 2015-06-24
      • 2012-04-08
      • 2021-07-22
      • 1970-01-01
      • 2013-01-09
      • 2011-09-27
      • 1970-01-01
      • 2022-01-17
      相关资源
      最近更新 更多