的.htaccess,迫使斜线和www [英] .htaccess, forcing a slash and www

查看:216
本文介绍了的.htaccess,迫使斜线和www的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以帮我,迫使我的网站重定向到使用WWW。并且总是在任何页面的末尾添加斜线?我的htaccess文件目前看起来是这样的:

Can someone please help me to force my website to redirect to using www. and ALWAYS add a slash at the end of any page? My htaccess file currently looks like this:

RewriteEngine on

RewriteRule blog/date/([^/]+)/?$ index.php?page=viewblog&date=$1
RewriteRule blog/([^/]+)/?$ index.php?page=viewblog&category=$1
RewriteRule blog/([^/]+)/([^/]+)/?$ index.php?page=viewblog&category=$1&title=$2

RewriteRule ^([^/\.]+)/?$ index.php?page=$1 [L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([a-zA-Z0-9]+)

在预先感谢:)

推荐答案

这将适用于任何领域:

DirectorySlash on
RewriteCond %{HTTP_HOST} !^www [NC]
RewriteRule .* http://www.%{HTTP_HOST}%{REQUEST_URI} [L]

这将增加斜线必要的时候。 (%{REQUEST_URI} / 与根的请求,或 /不管如果您要求 domain.com/whatever )。它还不会放在两个斜杠( // )用于与其他解决方案做的主要领域。该 DirectorySlash 指令确保了斜杠增​​加了适当即使 WWW 已present。

This will add the slash when necessary. (%{REQUEST_URI} will be / with a request for root, or /whatever if you request domain.com/whatever.) It also won't put in two slashes (//) for the main domain as the other solution does. The DirectorySlash directive ensures the slash is added where appropriate even if the www is already present.

这篇关于的.htaccess,迫使斜线和www的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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