mod_rewrite:将现有文件重写为slu,,slu to现有文件
我的情况如下:我有我的本地服务器上的public/文件夹中的静态文件。 任何进来的请求应该被转发到该文件夹,但是如果该文件夹中的文件被直接访问,它应该是404或redirect到'slug'。 例: Request: /my-file Should rewrite to: /public/my-file.html URL should be: http://localhost/my-file Request: /public/my-file.html Should rewrite to: /public/my-file.html URL should be: http://localhost/my-file 我在.htaccess有以下规则和条件: RewriteCond %{DOCUMENT_ROOT}/public/%{REQUEST_URI}.html -f RewriteRule ^.*$ /public/$0.html [L,C] RewriteCond %{REQUEST_URI} ^/public RewriteRule ^public/(.+).html$ /$1 [R=301,L] 从上到下: /public/{request}.html文件是? 如果(1)为真,则重写:/ /public/{request}.html ,并链接到(3)以防止redirect循环 原始请求是以/public开头的吗? 如果(3)为真,并且原始请求匹配public/{request}.html : /{request} ,则重写。 另外制作一个301头,告诉我的浏览器和抓取工具页面已经永久移动了。 请求将再次贯穿所有规则 所以,如果我们做了这两个要求: 1. Request: /my-file /public/my-file.html计算结果为true; […]