如何重定向/directory/index.html和/directory/index.php到/目录/ [英] How to redirect /directory/index.html and /directory/index.php to /directory/
本文介绍了如何重定向/directory/index.html和/directory/index.php到/目录/的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我必须做一些重定向 - 的index.html和index.php来/.
我可以重定向 www.domain.com/index.html
和 www.domain.com/index.php
到 www.domain.com
这一行:
重写规则^指数\(PHP |?HTML)。$ http://www.mydomain.com/ [R = 301,L]
不过,我还是有问题,这样的网页:
-
www.domain.com/directory/index.html
- 返回 200 OK -
www.domain.com/directory/index.php
- 返回 300多种选择(不知道为什么)
是否有可能将其重定向到 www.domain.com/directory /
做这一切与一个规则呢?
如果这会有所帮助,这里有什么在我的.htaccess文件现在:
< IfModule mod_rewrite.c>
RewriteEngine叙述上
的RewriteBase /
## Redirecd的index.html和放大器; PHP来/
。重写规则^指数\(?PHP | HTML)$ HTTP://www...mydomain...com/ [R = 301,L]
## 301重定向的非www到www版本
的RewriteCond%{HTTP_HOST}!^ WWW \。
(。*)重写规则^ $ HTTP://www.% {HTTP_HOST} / $ 1 [R = 301,L]
##返回404状态code和显示404.html
ErrorDocument的404 /404.html
< / IfModule>
解决方案
试试这个code:
< IfModule mod_rewrite.c>
RewriteEngine叙述上
的RewriteBase /
## Redirecd的index.html和放大器; PHP来/
的RewriteCond%{} THE_REQUEST /index\.(html|php)[NC]
重写规则^指数\(?: HTML | PHP)(*?)$ / $ 1 [L,R = 302,NC,NE]
## 301重定向的非www到www版本
的RewriteCond%{HTTP_HOST}!^ WWW \。
(。*)重写规则^ $ HTTP://www.% {HTTP_HOST} / $ 1 [R = 301,L]
##返回404状态code和显示404.html
ErrorDocument的404 /404.html
< / IfModule>
I have to do some redirects - index.html and index.php to /.
I could redirect www.domain.com/index.html
and www.domain.com/index.php
to www.domain.com
with this line:
RewriteRule ^index\.(php|html?)$ http://www.mydomain.com/ [R=301,L]
However I still have problems with pages like these:
www.domain.com/directory/index.html
- returns 200 OKwww.domain.com/directory/index.php
- returns 300 multiple choices (don't know why)
Is it possible to redirect them to www.domain.com/directory/
and do it all with one rule one?
If this helps, here's what's in my .htaccess file now:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
## Redirecd index.html & php to /
RewriteRule ^index\.(php|html?)$ http://www...mydomain...com/ [R=301,L]
## 301 Redirect from non-www to www version
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
## Return 404 status code and display 404.html
ErrorDocument 404 /404.html
</IfModule>
解决方案
Try this code:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
## Redirecd index.html & php to /
RewriteCond %{THE_REQUEST} /index\.(html|php) [NC]
RewriteRule ^(.*?)index\.(?:html|php)$ /$1 [L,R=302,NC,NE]
## 301 Redirect from non-www to www version
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
## Return 404 status code and display 404.html
ErrorDocument 404 /404.html
</IfModule>
这篇关于如何重定向/directory/index.html和/directory/index.php到/目录/的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文