htaccess的重写给力的index.php [英] htaccess rewrite to force index.php

查看:182
本文介绍了htaccess的重写给力的index.php的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有链接的格式如下: http://www.EXAMPLE.com /index.php?page=pageid 他们也可在: http://www.EXAMPLE.com/?page=pageid

I have links that are in this format: http://www.EXAMPLE.com/index.php?page=pageid They are also available at: http://www.EXAMPLE.com/?page=pageid

如何把对那些没有的index.php文件名使用URL的index.php的一部分吗?

How can I redirect the ones without the index.php filename to use the index.php part of the url?

我在我的htaccess的文件等重新定向的规则,他们工作的罚款,我只是不知道如何强制index.php的一部分,包含查询字符串为好。

I have other re-direct rules in my htaccess file, and they are working fine, I just don't know how to force the index.php part and include the query string as well.

推荐答案

把下面的规则,你的.htaccess文件在你的网站的根目录

Put the following rules in your .htaccess file in the root of your site

RewriteEngine On
RewriteBase /

#only for the root directory
RewriteCond %{REQUEST_URI} ^/$
#if the uri is not already index.php
RewriteCond %{REQUEST_URI} !^/index.php [NC]
RewriteRule ^$ /index.php    [R=301,L]

如果有与其他规则仍然冲突,则可以进一步限制这个规则只是一个请求页= 加入followind条件重写规则之前,查询字符串参数上述

If there are still conflicts with your other rules, you can further limit this rule to just requests with a page= querystring param by adding the followind condition before the rewrite rule above

# to limit further to only the requests with a page= param
RewriteCond %{QUERY_STRING} ^([^&]+&)*page=.*$ [NC]

这篇关于htaccess的重写给力的index.php的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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