【问题标题】:Change a url via htaccess通过 htaccess 更改 url
【发布时间】:2012-12-10 14:29:16
【问题描述】:

我有一个网址是http://www.testingmyweb.comli.com的网站

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

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

我可以在.htaccess 文件中进行哪些更改?

【问题讨论】:

  • 请注意www.testingmyweb.comli.com 并不总是等于testingmyweb.comli.com,这取决于您的网络服务器设置
  • @ShivanRaptor 我认为在原始帖子中情况正好相反。但我不确定。
  • 我的 htaccess 文件编码如下。 # 不要删除这一行,否则 mod_rewrite 规则将停止工作 RewriteBase / RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME}\.html -f RewriteRule ^(.*)$ $1.html Redirect /TCWEB/home .html testingmyweb.comli.com 我能做些什么来制作这样的网址testingmyweb.comli.com
  • 您可以编辑问题并将更新放入其中吗?

标签: .htaccess url web


【解决方案1】:

根据您的评论,您的 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,但浏览器地址栏中的URL 仍然是http://www.testingmyweb.comli.com。第二条规则和Redirect 一样,除了它检查请求实际上是针对/TCWEB/home.html 发出的,而不是内部重写的URI。因此,当有人直接访问 /TCWEB/home.html 时,他们会被重定向到 /,然后应用第一条规则。

【讨论】:

  • 朋友们 我写了这两个代码,但它不起作用。 # 不要删除这一行,否则 mod_rewrite 规则将停止工作 RewriteBase / 现在我的文件看起来像这样。我做了什么
  • @user1925876 你看到上面的原始 htaccess 文件了吗?删除Redirect 行并将其替换为底部的灰色内容。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-03-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-04-01
相关资源
最近更新 更多