.htaccess掩码原始网址

时间:2019-01-23 15:39:52

标签: apache .htaccess

我有这个网址:

localhost:1001/project/index.html

如果我写这个URL:

localhost:1001/project/index.html.twig

我希望将其屏蔽为第一个(localhost:1001/project.index.html),但是处理的URL必须是第二个(不知道是否可能)。

我已经尝试了所有这些方法,但是我认为我在项目文件夹根目录下的.htaccess上的所有操作都是错误的,因为我没有想要的任何方法:

a)

RedirectMatch 302 /project/index.html.twig /project/index.html

b)

RedirectMatch 301 /project/index.html.twig /project/index.html

c)

RewriteCond %{HTTP_HOST} ^/project/index.html.twig$ [NC]
RewriteRule /project/index.html [R=301,L]

评论

我要获取的过程

  1. 我在浏览器中写道:localhost:1001/project/index.html.twig
  2. 我希望我的.htaccess将浏览器中的URL转换为localhost:1001/project/index.html并在浏览器中看到该URL
  3. 之后,我想在内部处理原始URL:localhost:1001/project/index.html.twig

1 个答案:

答案 0 :(得分:0)

如果要进行外部重定向,这可能是您要寻找的:

RewriteEngine on
RewriteRule ^/?project/index\.html$ /project/index.html.trig [R=301]
RewriteRule ^/?project/index\.html\.twig$ /project/index.html [END]

如果要进行内部重写,请使用该变体:

RewriteEngine on
RewriteRule ^/?project/index\.html\.twig$ /project/index.html [R=301]
RewriteRule ^/?project/index\.html$ /project/index.html.trig [END]

这些规则应该在http服务器主机配置或动态配置文件(“ .htaccess”样式文件)中同样起作用。如果可以访问,您绝对应该首选第一个选项。如果需要使用动态配置文件,请确保完全启用了它的解释功能,并且该文件位于主机的DOCUMENT_ROOT文件夹中。

如果使用该规则收到服务器内部错误(http状态500),则可能是您操作了旧版本的apache http服务器。在这种情况下,您将在http服务器错误日志文件中的未知[END]标志上找到明确的提示。在这种情况下,请尝试使用较旧的[L]标志,尽管它取决于您的设置,但在这里它可能会起作用。

相关问题