的.htaccess和robots.txt的重写URL如何 [英] .htaccess and robots.txt rewrite url how to

查看:132
本文介绍了的.htaccess和robots.txt的重写URL如何的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是我的$ C $下的.htaccess

  RewriteEngine叙述上
重写规则(。*)的index.html
 

问题:当访问mydomain.com/robots.txt然后再次页面重定向到index.html的
要求:

 如果(URL包含的robots.txt)然后
    重定向到mydomain.com/robots.txt~~V
其他
    重定向到的index.html
 

解决方案

试试这个:

  RewriteEngine叙述上

的RewriteCond%{} REQUEST_FILENAME!-f
的RewriteCond%{} REQUEST_FILENAME!-d
重写规则(。*)的index.html
 

基本上,这两个的RewriteCond 告诉Apache重写URL的仅在所需的文件( -f )或目录( -d )不存在(即作为否定)

另外,如果你需要它只是为的robots.txt 您可以使用类似:

 的RewriteCond%{REQUEST_URI}!^ / robots.txt的$
 

而不是两个的RewriteCond 以上。

Here is my code for .htaccess

RewriteEngine on
RewriteRule (.*) index.html

Problem : when visit mydomain.com/robots.txt then page again redirect to index.html
Required :

if(url contain robots.txt) Then   
    redirect to mydomain.com/robots.txt   
else   
    redirect to index.html

解决方案

Try this:

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) index.html

Basically, those two RewriteCond tell apache to rewrite the URL only if the requested file (-f) or directory (-d) doesn't exists (the ! serves as a negation).

Alternatively, if you need it just for robots.txt you can use something like:

RewriteCond %{REQUEST_URI} !^/robots.txt$

instead of the two RewriteCond above.

这篇关于的.htaccess和robots.txt的重写URL如何的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆