强制页面以斜杠结束并重写URL

时间:2011-06-26 21:56:39

标签: .htaccess

我必须以这种方式打电话给我的页面:

http://example.com/index.php?page=homepage

我想总是以这种方式显示网址

http://example.com/homepage

同时我也想阻止在网址末尾插入/ ...所以:

http://example.com/homepage/ or http://example.com/homepage

指向同一页面。 我怎么能用htacces做这个技巧?我要纠正我的HTML中文件的所有相对路径吗?

非常感谢

2 个答案:

答案 0 :(得分:1)

# activate Rewrite Engine
RewriteEngine On
# do not do anything for already existing files
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule .+ - [L]

# remove trailing slash
RewriteRule ^(.+)/$ $1 [R=301,L,QSA]
# rewrite all other requests to index.php
RewriteRule ^(.*)$ index.php?page=$1 [QSA,L]

答案 1 :(得分:0)

RewriteEngine on
RewriteBase /
RewriteRule ^(css|js)/(.*)?$ $1/$2 [L]
RewriteRule ^(.*)$ index.php?page=$1 [L,QSA]
RewriteRule ^(.*)/$ $1 [R]

this的上次更新。