如何强制htaccess没有www网址

时间:2012-12-06 10:53:58

标签: .htaccess url

我的htaccess现在:

# Use PHP 5.3
AddType application/x-httpd-php53 .php


RewriteEngine On
RewriteBase /

#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller,
#previously this would not have been possible.
#'system' can be replaced if you have renamed your system folder.

RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]

#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn't true it sends the
#request to index.php

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

# If we don't have mod_rewrite installed, all 404's
# can be sent to index.php, and everything works as normal.
# Submitted by: ElliotHaughin

ErrorDocument 404 /index.php

我需要做一个规则,如果有人输入http://www.mypage.com/blog/blablatitle

它将他重定向到http://mypage.com/blog/blablatitle

和首页和所有页面相同。

我正在使用CodeIgniter,但我认为在处理htaccess时这并不是那么重要。

这个建议的解决方案在CodeIgniter中运行不正确:

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

因为它在地址中添加了index.php,例如:当我输入时:

http://www.mypage.com/blog/blablatitle

它将我重定向到:

http://mypage.com/index.php?/blog/blablatitle

我需要:

http://mypage.com/blog/blablatitle

没有这个规则就可以了(没有索引,php),例如:http://mypage.com/blog/blablatitle

那么,如何改进此重定向规则som index.php的任何建议都不会出现在重定向的链接中?

2 个答案:

答案 0 :(得分:1)

解决了! ;)你需要在

之后把它放好
RewriteBase /

答案 1 :(得分:1)

请试试这个:

RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]

RewriteRule ^index.php(.*)$ http://%1/$1 [R=301,L]