的.htaccess - 重定向非www到www的网址后,pretty的网址丢失 [英] .htaccess - pretty url lost after redirecting non-www to www urls
问题描述
我已经做的.htaccess 301重定向到reirect非WWW到www,这是工作的罚款,但是当一个页面与非WWW网址访问我的pretty的URL丢失。
我已经做了这样的看法。
选项+了FollowSymLinks
RewriteEngine叙述上
的RewriteCond%{HTTP_HOST} ^ site.com [NC]
重写规则^(。*)$ http://www.site.com/$1 [R = 301,NC]
重写规则^([^ /] *)/工艺/ 1类= $&AMP(* \ HTML);?链接= $ 2 [L]
据重定向URL
http://www.site.com/software/page.html
要
http://www.site.com/process/index.php?category=software&link=page.html
正确没有松动pretty的网址 www.site.com/software/page.html
在地址栏中。
据重定向URL
http://site.com/software/page.html
要
http://www.site.com/process/index.php?category=software&link=page.html
正确,现在pretty的网址丢失,并在地址栏中的地址为
http://www.site.com/process/index.php?category=software&link=page.html
相反
的
http://site.com/software/page.html
如何保持pretty的URL时,加www被访问的页面。
请参阅并建议没有办法做到这一点。
感谢
我认为问题是缺少→
标志中的第一条规则。试试这个code:
选项+了FollowSymLinks -MultiViews
#开启mod_rewrite的上
RewriteEngine叙述上
的RewriteBase /
的RewriteCond%{HTTP_HOST} ^网站\ .COM $ [NC]
重写规则^(。*)$ http://www.site.com/$1 [R = 301,NC,L]
重写规则^([^ /] +)/([^] + \ HTML)$ /工艺/类1 = $&放大器;环= $ 2 [QSA,L,NC]
I have made .htaccess 301 redirect to reirect non www to www, which is working fine but my pretty url is lost when a page is accessed with non www url.
I have done it this way.
Options +FollowSymlinks
RewriteEngine on
Rewritecond %{HTTP_HOST} ^site.com [NC]
Rewriterule ^(.*)$ http://www.site.com/$1 [R=301,NC]
RewriteRule ^([^/]*)/(.*\.html) process/?category=$1&link=$2 [L]
It redirects url
http://www.site.com/software/page.html
To
http://www.site.com/process/index.php?category=software&link=page.html
Properly without loosing pretty url www.site.com/software/page.html
in address bar.
It redirects url
http://site.com/software/page.html
To
http://www.site.com/process/index.php?category=software&link=page.html
Properly and now pretty url is lost and address in address bar is
http://www.site.com/process/index.php?category=software&link=page.html
Instead of
http://site.com/software/page.html
How to keep pretty url when page is accessed without www.
Please see and suggest any way to do this.
Thanks
I believe problem is missing L
flag in your first rule. Try this code:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
Rewritecond %{HTTP_HOST} ^site\.com$ [NC]
Rewriterule ^(.*)$ http://www.site.com/$1 [R=301,NC,L]
RewriteRule ^([^/]+)/([^.]+\.html)$ /process/?category=$1&link=$2 [QSA,L,NC]
这篇关于的.htaccess - 重定向非www到www的网址后,pretty的网址丢失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!