【问题标题】:codeigniter htaccess 301代码点火器 htaccess 301
【发布时间】:2013-03-15 00:20:44
【问题描述】:

大家好,我有用于 codeigniter 的普通 htaccess 文件,我想 301 一个 url 到另一个

我不得不混淆链接才能发布:(

ie h2tp://www domain com/controller/method/value1 ->h2tp://www domain com/controller/method/value2

但是我玩得很开心......

这是htaccess

    <IfModule mod_rewrite.c>
        RewriteEngine On
        RewriteBase /

        RewriteRule ^(home(/index)?)/?$ / [L,R=301]
        RewriteRule ^(.*)/index/?$ $1 [L,R=301]


        #Removes trailing slashes 
        #had to remove ajaxquery search else it fails
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteCond %{REQUEST_URI} !(search/ajaxsearch)
        RewriteRule ^(.+)/$ $1 [L,R=301]


        #Rewrite all non-www to www based filenames
        #should get rid of any canonical issues
        RewriteCond %{HTTP_HOST} ^domain\.es [NC]
        RewriteRule ^(.*)$ http://www.domain\.es/$1 [R=301,L]


        #Removes access to the system folder by users.
        #Additionally this will allow you to create a System.php controller,
        #previously this would not have been possible.
        #'system' can be replaced if you have renamed your system folder.
        RewriteCond %{REQUEST_URI} ^system.*
        RewriteRule ^(.*)$ /index.php?/$1 [L]

        #Checks to see if the user is attempting to access a valid file,
        #such as an image or css document, if this isn't true it sends the
        #request to index.php
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteRule ^(.*)$ index.php?/$1 [L]



    </IfModule>

    <IfModule !mod_rewrite.c>
        # If we don't have mod_rewrite installed, all 404's
        # can be sent to index.php, and everything works as normal.
        # Submitted by: ElliotHaughin

        ErrorDocument 404 /index.php
    </IfModule>[/code][/quote]

如果我放

    Redirect 301 /controller/method/value1 h2tp://www domain com/controller/method/value2 

我明白了

h2tp://www 域 com/controller/method/value2?controller/method/value1

我已经花了好几个小时了,这让我很生气:)

【问题讨论】:

  • 有什么理由不只使用 CI 的内置路由?
  • 我真的需要 Ci 给你的 301 吗?
  • 不,抱歉,这只是一个内部重定向。

标签: .htaccess codeigniter redirect


【解决方案1】:

由于我对 htaccess 完全缺乏了解,我试图在这些行下方添加 301 重定向。

    #Checks to see if the user is attempting to access a valid file,
    #such as an image or css document, if this isn't true it sends the
    #request to index.php
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?/$1 [L]

到那时所有检查都已运行,[L] 标志正在停止运行检查。

所以当我在以下几行上方发布正常的 301 重定向时,它起作用了。

    #Removes access to the system folder by users.
    #Additionally this will allow you to create a System.php controller,
    #previously this would not have been possible.
    #'system' can be replaced if you have renamed your system folder.
    RewriteCond %{REQUEST_URI} ^system.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]

【讨论】:

    猜你喜欢
    • 2011-07-28
    • 1970-01-01
    • 2016-10-20
    • 2015-11-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多