Htaccess用于避免index.php?page =来自URL

时间:2013-10-11 05:29:27

标签: .htaccess

我的项目包含http://domain.com/index.php?page=home/contactushttp://domain.com/index.php?page=events/announcementdetails/80等网址。

我想避免 index.php?page = 以及给定网址中的80之类的参数,并希望将网址更改为http://domain.com/home/contactushttp://domain.com/events/announcementdetails。如何使用htaccess文件实现此目的。

2 个答案:

答案 0 :(得分:0)

尝试将此添加到文档根目录中的htaccess文件:

RewriteEngine On

RewriteCond %{THE_REQUEST} \ /index\.php\?([^\ ]*)
RewriteRule ^ /%1 [L,R=301]

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

答案 1 :(得分:0)

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

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]