.htaccess HttAccess重定向对于www和非www的情况不同
我已使用以下命令将所有非www重定向到www url.htaccess HttAccess重定向对于www和非www的情况不同,.htaccess,url-redirection,.htaccess,Url Redirection,我已使用以下命令将所有非www重定向到www url RewriteCond %{HTTP_HOST} !^www\. [NC] RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L] 其次,, 所需类别的最终url为: http://www.slidecorner.com/category/Design 我用它来实现这一目标 RewriteRule ^/?category/(.*) category.php?ctitle=$1
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
其次,,
所需类别的最终url为:
http://www.slidecorner.com/category/Design
我用它来实现这一目标
RewriteRule ^/?category/(.*) category.php?ctitle=$1
这同样有效,但当我在任何重定向检查网站中检查此url时,“www”版本的url是完美的,但“非www”url在内部重定向到:
http://www.slidecorner.com/category.php/Design?ctitle=Design
这对搜索引擎有好处吗?请告知
更新:也尝试了[L]标志,并且rewritebase已经存在。附上完整的HTC访问权限以供参考
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^docs$ docs.php
RewriteRule ^category$ category.php
RewriteRule ^categories$ categories.php
RewriteRule ^members$ members.php
RewriteRule ^upload$ upload.php
RewriteRule ^search$ search.php
RewriteRule ^account$ account.php
RewriteRule ^logout$ logout.php
RewriteRule ^login$ login.php
RewriteRule ^signup$ signup.php
RewriteRule ^feeds$ feeds.php
RewriteRule ^mydocs$ mydocs.php
RewriteRule ^myfav$ myfavoritedocs.php
RewriteRule ^doc/(.*)/(.*) viewdoc.php?did=$1&title=$2
RewriteRule ^syndicate/docs/(.*)/(.*) syndicatedocs.php?filter=$1&title=$2
RewriteRule ^download/doc/(.*)/(.*) downloaddoc.php?DID=$1&title=$2
RewriteRule ^resetpassword/(.*) resetpassword.php?code=$1
RewriteRule ^confirmemail/(.*) confirmemail.php?code=$1
RewriteRule ^resendconfirmation/(.*) resendconfirmation.php?userid=$1
RewriteRule ^members/profile/(.*)/(.*) memberprofile.php?pid=$1&username=$2
RewriteRule ^/?category/(.*) category.php?ctitle=$1 [L]
# to hide jpg images
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^http://(www\.)?slidecorner.com[NC]
RewriteCond %{HTTP_REFERER} !^http://(www\.)?slidecorner.*$ [NC]
RewriteRule \.(jpeg|jpg)$ - [F]
# to hide jpg images
# for sending compressed data to load faster
AddOutputFilterByType DEFLATE text/html text/plain text/xml application/xml application/xhtml+xml text/javascript text/css application/x-javascript
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4.0[678] no-gzip
BrowserMatch bMSIE !no-gzip !gzip-only-text/html
# for sending compressed data to load faster
</IfModule>
# For security reasons, Option followsymlinks cannot be overridden.
#Options +FollowSymLinks
Options +SymLinksIfOwnerMatch
#non www redirect ,since the above doesnt redirect
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
## EXPIRES CACHING ##
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access 1 year"
ExpiresByType image/jpeg "access 1 year"
ExpiresByType image/gif "access 1 year"
ExpiresByType image/png "access 1 year"
ExpiresByType text/css "access 1 month"
ExpiresByType text/html "access 1 month"
ExpiresByType application/pdf "access 1 month"
ExpiresByType text/x-javascript "access 1 month"
ExpiresByType application/x-shockwave-flash "access 1 month"
ExpiresByType image/x-icon "access 1 year"
ExpiresDefault "access 1 month"
</IfModule>
## EXPIRES CACHING ##
<IfModule mod_security.c>
# Turn off mod_security filtering.
SecFilterEngine Off
# The below probably isn't needed,
# but better safe than sorry.
SecFilterScanPOST Off
</IfModule>
Options -Indexes
我删除了它,url很好。另外,非www到www重定向被完全停止,因为我删除了它
上面的代码有什么问题吗 指令的顺序(模块内)在.htaccess中很重要。虽然您的问题表明您首先执行规范的www
重定向,但实际上在.htaccess文件中进行内部重写后会出现这种情况,在这种情况下,这肯定是一个问题。(尽管您从“检查工具/网站”获得的确切输出似乎是“工具”的错误。)
通常,在内部重写之前,应该始终具有外部重定向
先进行内部重写,最终会丢失“漂亮的URL”。当您访问非规范(非www
)URLhttp://example.com/category/Design
是:
/category.php?ctitle=Design
http://www.example.com/category.php?ctitle=Design
必须认识到,
L
(last
)标志只会停止规则集的当前处理。如果发生了内部或外部重定向,则进程将再次启动 用你的问题修改编辑更新:在问题中做了更正在浏览器的地址栏中放置非www?获取正确位置?当我放置非www版本时,它重定向到Hey w3d,这就像一个符咒。我将www重定向移到了顶部,它成功了。我是htaccess的新手,不知道这一点。谢谢
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]