如何重定向/directory/index.html和/directory/index.php到/目录/重定向、目录、directory、index

由网友(hobo (流浪者 ))分享简介:我必须做一些重定向 - 的index.html和index.php来/.我可以重定向 www.domain.com/index.html 和 www.domain.com/index.php 到 www.domain.com 这一行:重写规则^指数\(PHP |?HTML)。$ http://www.mydomain....

我必须做一些重定向 - 的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>
 
飞冰 ICE 下载 Iceworksv1.32 官方版 腾牛下载

解决方案

试试这个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 OK www.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>

阅读全文

相关推荐

最新文章