2013-03-10 84 views
-1

我想从URL中删除“http://”和“https://”。我也想删除“www”。也是它的一部分。全部使用mod重写/ .htaccess。我在这里找到的大多数相关答案都是使用PHP或JavaScript。如何删除“http://”,“https://”和“www。”从一个URL使用国防部重写?

e.g, 
"http://www.example.com" should become "example.com" 
"https://example.com" should become "example.com" 
"www.example.com" should become "example.com" 

回答

1

http://https://是协议说明符。浏览器可以为用户隐藏它们,但它们不能通过modrewrite从URL中删除。

为Apache modrewrite剥去www.,使用

RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC] 
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]