【发布时间】:2021-05-15 13:39:17
【问题描述】:
我正在使用 .htaccess 重写以从我的网站中删除“.html”扩展名。但是,我在函数中使用 URL 将参数传递给另一个页面 (mysite.com/locations#12345)
我的重写规则如下:
RewriteCond %{THE_REQUEST} /([^.]+)\.html [NC]
RewriteRule ^ /%1 [NC,L,R]
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^ %{REQUEST_URI}.html [NC,L]
我试过这样做:
RewriteCond %{THE_REQUEST} /locations/([^.]+) [NC]
RewriteRule ^ /locations%1 [NC,L,R]
但我得到“mysite.com/locations%20HTTP/2#12345”
【问题讨论】:
-
你的原始网址是什么,应该重定向什么网址?
-
我正在请求“mysite.com/locations#12345”,但我使用的重写规则是重写它。如果我删除我的覆盖尝试,我当前的规则会将该 URL 设为“mysite.com/locations/#12345”-“/”不能存在,因为它会将我带到位置 / 目录而不是页面。跨度>
-
您的原始规则只是从 URL 中删除
.html,但您在mysite.com/locations#12345中没有.html -
即使我请求“mysite.com/locations.html#12345”,它也会被重写为“mysite.com/locations/#12345 - 请求使用或不使用“.html”会产生相同的重写前两个条件。
-
如果
locations是一个真实目录,那么mod_dir会自动添加一个斜杠。你有一个名为locations.html的文件和一个名为locations/的目录吗?
标签: html apache .htaccess mod-rewrite url-rewriting