【发布时间】:2015-09-14 07:10:05
【问题描述】:
我想将非 www 重定向到 www 网址,它工作正常,除了
http://wellnessvisit.com/blog/
我想将此重定向到
http://www.wellnessvisit.com/blog/
虽然它在所有其他网址上都可以正常工作,但不适用于此
下面是我的.htaccess 文件
RewriteEngine on
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php
RewriteRule ^index\.php$ / [L,R=301]
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteRule doctor-(.*)\.htm$ doctor-details.php?doc_id=$1
RewriteRule hospital-(.*)\.htm$ hospital_detail.php?hosp_spec_id=$1
RewriteRule hotel-(.*)\.htm$ hotel_details.php?hotel_id=$1
RewriteRule destination-(.*)\.htm$ destination_details.php?dest_id=$1
RewriteRule news-(.*)\.htm$ news-details.php?news_id=$1
RewriteRule article-(.*)\.htm$ articles-details.php?article=$1
RewriteRule service-(.*)\.htm$ service-details.php?service_id=$1
RewriteRule user-register.php$ register.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/$ /$1 [R=301,L]
#adds ".php" to a URL that isn't a directory or a file
RewriteCond %{REQUEST_URI} !(\.[^./]+)$
RewriteCond %{REQUEST_fileNAME} !-d
RewriteCond %{REQUEST_fileNAME} !-f
RewriteRule (.*)$ $1.php
【问题讨论】:
-
我认为,您正确地进行了重定向。关于它有一个旧答案:stackoverflow.com/questions/12050590/…。也许,还有什么问题?
-
那条 www 规则对我来说看起来不错。但没有检查其余部分,因为问题是具体的。
-
@user4035 哪里错了?我没有在我的代码中添加任何条件,这是完整的 mt .htaccess 文件
-
@user4035 有两个 .htaccess 文件,一个在根目录,第二个在博客
-
@user4035 我现在修改并保存博客 .htaccess 文件,当我点击博客时,它会重定向到索引页面。我不知道为什么会这样
标签: php apache .htaccess mod-rewrite redirect