【问题标题】:Codeginter 301 redirectCodeigniter 301 重定向
【发布时间】:2014-08-27 06:59:46
【问题描述】:

我有一个正在运行的网站。它在 url 中使用 index.php 开始了生活。我已经把它去掉了,但为了不重复内容,我需要对任何可能存在但仍使用 index.php 的现有路径进行 301 重定向。

我的 .htaccess 文件如下所示:

RewriteEngine on

RewriteCond $1 !^(index\.php|robots\.txt|public|)

# Prevent CI index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]


RewriteRule   ^register   /index.php/register/ [L]

这对 domain.com/register 很有效

如何将 domain.com/index.php/register 也设为 301,但仍仅在地址栏中保留 domain.com/register?

提前致谢。

【问题讨论】:

    标签: .htaccess codeigniter mod-rewrite


    【解决方案1】:

    尝试将其添加到最顶部(就在RewriteEngine on 下方):

    RewriteCond %{THE_REQUEST} \ /+index\.php([^\?\ ]*)
    RewriteRule ^ /%1 [L,R=301]
    

    【讨论】:

    • 快到了!! domain.com/index.php/register 现在在地址栏中重写为 domain.com//register。任何想法如何删除不需要的正斜杠?谢谢
    • @lunchboxbill 是的,将index\.php([^\?\ ]*) 更改为index\.php/([^\?\ ]*)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-09
    • 2015-02-10
    • 2018-12-26
    • 1970-01-01
    • 2018-08-06
    • 1970-01-01
    相关资源
    最近更新 更多