.htaccess RewriteRule将url屏蔽到文件

时间:2016-09-26 19:20:27

标签: .htaccess

我正在尝试使用.htaccess将网址屏蔽为pdf文件。 Chrome和Edge始终打开文件并显示网址。我使用301重定向来创建一个链接到文件的别名网址,但这似乎不是正确的方法。

现在我尝试以下方式:

RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php
RewriteRule ^agb?$ wp-content/uploads/2016/07/AGB.pdf$ [L]

我通过以下方式测试:http://htaccess.mwl.be/

我希望用“agb”代替整个wordpress部分来掩盖pdf文件的网址。

似乎第一次重写规则搞砸了我的计划,但此刻我完全在猜测。

提前致谢。

*编辑:

我设法更改了.htaccess,现在它重定向:

RewriteEngine On
RewriteBase /
RewriteRule ^agb$ wp-content/uploads/2016/07/AGB.pdf$ [L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php

但我不明白的是,浏览器中的网址发生了变化。我认为RewriteRules用于屏蔽URL,因此用户在更改后不会看到URL发生的更改。

在我的情况下,用户应该只看到/ agb - 而是显示文件的整个URL。

0 个答案:

没有答案