通过htaccess更改网址

时间:2012-12-24 03:29:30

标签: .htaccess url web

我有一个网址,网址为http://www.testingmyweb.comli.com

在我的网站上有一个文件夹TCWEB。我的网站在这个文件夹中。

我想将http://testingmyweb.comli.com/TCWEB/home.html映射到http://testingmyweb.comli.com/

我可以在.htaccess文件中做些什么更改?

1 个答案:

答案 0 :(得分:0)

根据您的评论,您的htaccess文件如下所示:

RewriteBase /
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html

Redirect /TCWEB/home.html testingmyweb.comli.com

您已将.html附加到html文件请求(但没有扩展名)的规则。您下面的重定向需要删除。为了将/重写为/TCWEB/home.html,该mod_alias指令将导致循环。将其替换为以下规则:

RewriteRule ^$ /TCWEB/home.html [L]
RewriteCond %{THE_REQUEST} /TCWEB/home.html
RewriteRule ^ / [L,R=301]

第一条规则使/的请求映射到/TCWEB/home.html,但浏览器地址栏中的网址仍为http://www.testingmyweb.comli.com。第二条规则执行Redirect所做的事情,除了它检查请求是否实际是针对/TCWEB/home.html而不是内部重写的URI。因此,当有人直接转到/TCWEB/home.html时,会将其重定向到/,然后会应用第一条规则。