ModRewrite 在删除 WWW 时出现奇怪的重定向行为
我试图在我的项目中使用一些规则来从 URL
开头删除 www
,但我遇到了一些问题。
我的服务器结构是:
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
是站点文件夹,content+name
是内容变量,创建用于从数据库检索页面。
该网站与此规则完美配合
RewriteEngine On
RewriteRule ^(page\+type/)([a-zA-Z0-9_+-]+)[/]?$ page_folder/page.php?varname=$2
我的目的是删除 www
,因此我添加了此规则,但它无效
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.domain.com$ [NC]
RewriteRule ^(.*)$ http://domain.com$1 [R=301,L]
RewriteRule ^(page\+type/)([a-zA-Z0-9_+-]+)[/]?$ page_folder/page.php?varname=$2
如果我在前面输入 www
,我的问题就会出现我的域名:
此方法
http://domain.com/beta_folder/page+type/content+name
如果我删除 www
规则,则如果我编写
http://www.domain.com/beta_folder/page+type/content+name
重写规则将我重定向,则
http://www.domain.compage+type/content+name
有效,不幸的是,问题仍然存在
,我基本上无法对我的域进行公开测试
,如果我编写的
http://www.domain.com/beta_folder
规则将我发送到我
http://domain.com/
发现解决问题的唯一方法是写入我的网站所在的文件夹,所以:
RewriteCond %{HTTP_HOST} ^www.domain.com$ [NC]
RewriteRule ^(.*)$ http://domain.com/beta_folder/$1 [R=301,L]
我不明白为什么我应该写入该文件夹,因为我的重写条件会影响 http://www.domain.com/folder_name/contents
而不是 http://www.domain.com/contents
为什么缺少 folder_name
从重写?
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$ [NC]
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 affectshttp://www.domain.com/folder_name/contents
and not http://www.domain.com/contents
why folder_name
missing from the rewriting?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
试试这个与您的规则略有不同的示例:
如果这不能解决您的问题,请大声喊出来。
Try this, subtly different example of your rule:
Shout out if this doesn't solve your problem.