重写网址的index.php,但要避免在URL中的index.php [英] Rewrite URL to index.php but avoid index.php in the URL

查看:353
本文介绍了重写网址的index.php,但要避免在URL中的index.php的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在内部重定向所有请求的index.php和外部重定向所有包含的index.php使用.htaccess文件的请求。

所以像网址的http://主机/测试应该由index.php文件和URL一样的 HTTP://host/index.php/test 应该被重定向到的的http://主机/测试,然后再由index.php文件处理(不将浏览器重定向到index.php)

我尝试以下,但总是得到一个消息太多的重定向。

 重写规则^指数\ .PHP /?(.*)$ / $ 1 [R,L]
重写规则。*的index.php / $ 0 L]
 

解决方案

您需要看看在请求行的URL,看看 /index.php/... 已请求:

 的RewriteCond%{THE_REQUEST} ^ GET \ /index\.php/?([^] *)
重写规则^指数\ .PHP /?(.*)/ $ 1 [R,L]
的RewriteCond $ 0 ^指数\的.php($ | /)!
重写规则。*的index.php / $ 0 L]
 

I'm trying to internally redirect all requests to index.php and externally redirect all requests that contain index.php using a .htaccess file.

So URLs like http://host/test should be processed by index.php and URLs like http://host/index.php/test should be redirected to http://host/test and then processed by index.php (without redirecting the browser to index.php)

I tried the following but always get a message "Too many redirects...":

RewriteRule ^index\.php/?(.*)$ /$1 [R,L]
RewriteRule .* index.php/$0 [L]

解决方案

You need to look at the URL in the request line to see if /index.php/… has been requested:

RewriteCond %{THE_REQUEST} ^GET\ /index\.php/?([^ ]*)
RewriteRule ^index\.php/?(.*) /$1 [R,L]
RewriteCond $0 !^index\.php($|/)
RewriteRule .* index.php/$0 [L]

这篇关于重写网址的index.php,但要避免在URL中的index.php的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆