简体   繁体   English

创建临时重定向将“index.php”添加到 url

[英]Create temporary redirect adding "index.php" into url

If user requests this page:如果用户请求此页面:

example.com/asdf/jkl?qwer=ty

I want them redirected to我希望他们重定向到

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

I believe 307 is probably the appropriate status code.我相信 307 可能是适当的状态代码。 I just need to add in "index.php" after the domain name for every request.我只需要在每个请求的域名后添加“index.php”。 But... images on the page are still found at example.com/image/asdf.jpg .但是...页面上的图像仍然可以在example.com/image/asdf.jpg找到。 I don't know if an .htaccess directive would affect in-line resource requests or not, but I would need it not to.我不知道.htaccess指令是否会影响.htaccess资源请求,但我不需要它。

The reason I need this is that we are having a problem with our site that is requiring us to add "index.php" into urls.我需要这个的原因是我们的网站有问题,需要我们将“index.php”添加到网址中。 Hopefully we can fix it soon.希望我们能尽快修复它。 But meanwhile, our Google indexed search results are leading to 404 errors.但与此同时,我们的 Google 索引搜索结果导致 404 错误。

EDIT:编辑:

I tried this:我试过这个:

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

Testing this on example.com/asdf/jkl , it results in example.com/index.php/index.php/index.php/.../index.php/asdf/jkl where "index.php" is repeated a bunch of times.example.com/asdf/jkl上进行测试,结果是example.com/index.php/index.php/index.php/.../index.php/asdf/jkl其中“index.php”重复了一堆次。 Sometimes I also get a message about a redirect loop.有时我也会收到有关重定向循环的消息。

You can use this code in your DOCUMENT_ROOT/.htaccess file:您可以在DOCUMENT_ROOT/.htaccess文件中使用此代码:

RewriteEngine On
RewriteBase /

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM