【问题标题】:Create temporary redirect adding "index.php" into url创建临时重定向,将“index.php”添加到 url
【发布时间】:2015-06-13 23:46:10
【问题描述】:

如果用户请求此页面:

example.com/asdf/jkl?qwer=ty

我希望他们重定向到

example.com/index.php/asdf/jkl?qwer=ty

我相信 307 可能是合适的状态码。 我只需要在每个请求的域名后添加“index.php”。 但是...页面上的图像仍然可以在example.com/image/asdf.jpg 找到。我不知道.htaccess 指令是否会影响内联资源请求,但我不需要它。

我需要这个的原因是我们的网站有a problem,这要求我们将“index.php”添加到网址中。希望我们能尽快修复它。但与此同时,我们的 Google 索引搜索结果导致 404 错误。

编辑:

我试过了:

RewriteBase /
RewriteRule ^/index - [L] # stop rule processing if request already starts with "index.php"
RewriteRule ^(.*) index.php/$1 [L,R]

example.com/asdf/jkl 上进行测试,结果是example.com/index.php/index.php/index.php/.../index.php/asdf/jkl,其中“index.php”重复了很多次。有时我还会收到有关重定向循环的消息。

【问题讨论】:

    标签: regex apache .htaccess mod-rewrite redirect


    【解决方案1】:

    您可以在DOCUMENT_ROOT/.htaccess 文件中使用此代码:

    RewriteEngine On
    RewriteBase /
    
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^((?!index.php/).*)$ index.php/$1 [L,NC]
    

    【讨论】:

    • 这似乎工作得很好。我想如果我想实际重定向,我可以将结尾更改为 [L,NC,R=302]
    • 是的,如果您想更改 URL,请使用:RewriteRule ^((?!index.php/).*)$ index.php/$1 [L,NC,R=302]
    猜你喜欢
    • 1970-01-01
    • 2012-03-18
    • 2013-12-27
    • 1970-01-01
    • 1970-01-01
    • 2014-01-14
    • 2010-10-24
    • 2016-12-26
    • 2014-09-16
    相关资源
    最近更新 更多