避免从URL引用index.php?page =的htaccess [英] Htaccess for avoiding index.php?page= from URL

查看:75
本文介绍了避免从URL引用index.php?page =的htaccess的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的项目有类似 http://domain.com/index.php?page之类的URL。 = home / contactus http://domain.com/index。 php?page = events / announcementdetails / 80 等。

我想避免使用 index.php?page = 和给定URL中的参数(例如80),并希望将URL更改为 http://domain.com/home/contactus http://domain.com/events/announcementdetails 。我该如何使用htaccess文件来实现这一点。

I want to avoid the index.php?page= and the parameters like 80 in the given URL and want to change the URL to http://domain.com/home/contactus and http://domain.com/events/announcementdetails. How can I achieve this using htaccess file.

推荐答案

启用 mod_rewrite .htaccess 通过 httpd.conf ,然后将此代码放入 DOCUMENT_ROOT / .htaccess 文件:

Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your DOCUMENT_ROOT/.htaccess file:

RewriteEngine On

RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+index\.php\?page=([^\s&]+) [NC]
RewriteRule ^ /%1? [R=301,L,NE]

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

这篇关于避免从URL引用index.php?page =的htaccess的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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