我试图用htacess编写一个多重重写函数。
它应处理所有案件:
http://www.example.com/about.html
应该重写为
http ://example.com/约
但当然,如果只有一个项目需要重写,它也应该有效:
http://example.com/about
应该重写为
http ://example.com/约
下面是我的代码(https和no-WWW工作,但是注释的no-.html不起作用)。
请注意,在重写时,您需要使用先前重写的URL,而不是用户在地址栏中键入的内容,否则规则将覆盖另一条规则所做的更改。
RewriteEngine on
#strip the www
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [L,R=301]
#remove .html if any
#RewriteCond %{REQUEST_FILENAME}.html -f
#RewriteRule ^(([^/]*/)*[^/.]+)$ /$1.html [L]
#switch to https
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [L,R=301]
# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# otherwise forward it to index.php
RewriteRule . index.php
# Disable the server signature
ServerSignature Off发布于 2014-03-24 19:19:25
您可以使用:
RewriteEngine on
#strip the www
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [L,R=301]
#switch to https
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [L,R=301]
#remove .html if any
RewriteCond %{THE_REQUEST} \s/+(?:index)?(.*?)\.html[\s?] [NC]
RewriteRule ^ /%1 [R=301,L,NE]
# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# otherwise forward it to index.php
RewriteRule . index.php
# Disable the server signature
ServerSignature Offhttps://stackoverflow.com/questions/22618299
复制相似问题