ModRewrite weird redirect behavior on removing WWW
I'm trying to use some rule on my project to remove www
from the beginning of the URL
but I've some problem.
my server structure is:
domain.com/beta_folder
domain.com/beta_folder/page+type
domain.com/beta_folder/page+type/content+name
domain.com/beta_folder/page+type/content+name/edit
domain.com/beta_folder/page+type/content+name/etc.
domain.com/beta_folder/.htaccess //here is where my htaccess is
beta_folder
is the site folder, and content+name
are content vars, created to retrieve pages from the database.
the site works perfect with this rules
RewriteEngine On
RewriteRule ^(page\+type/)([a-zA-Z0-9_+-]+)[/]?$ page_folder/page.php?varname=$2
My intention was to remove www
, so I've added this rule but it isn't effective
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.domain.com$ [N开发者_StackOverflow中文版C]
RewriteRule ^(.*)$ http://domain.com$1 [R=301,L]
RewriteRule ^(page\+type/)([a-zA-Z0-9_+-]+)[/]?$ page_folder/page.php?varname=$2
My problem starts if I digit www
in front of my domain name:
this works
http://domain.com/beta_folder/page+type/content+name
if i write
http://www.domain.com/beta_folder/page+type/content+name
the rewrite rule redirect me at
http://www.domain.compage+type/content+name
if i remove the www
rules, the problem still active
unfortunately, I can't make a public test for my domain
basically, if I write
http://www.domain.com/beta_folder
the rules sends me to
http://domain.com/
the only way I've found to solve the problem is to write the folder where my site is, so:
RewriteCond %{HTTP_HOST} ^www.domain.com$ [NC]
RewriteRule ^(.*)$ http://domain.com/beta_folder/$1 [R=301,L]
I don't undestand why I should write the folder, because my rewrite cond affects
http://www.domain.com/folder_name/contents
and not http://www.domain.com/contents
why folder_name
missing from the rewriting?
Try this, subtly different example of your rule:
RewriteCond %{HTTP_HOST} !^www.domain\.com$
RewriteRule (.*) http://domain.com/$1 [R=301,L]
Shout out if this doesn't solve your problem.
精彩评论