【发布时间】:2021-04-08 22:58:07
【问题描述】:
我正在尝试制作一个 .htaccess 代码来自动重写目录的规则。
例如:
URL: https://example.com/assets/test.png
Folder: /src/assets/test.png
或者,
URL: https://example.com/js/test.js
Folder: /src/js/test.js
我的 htaccess 文件:
#Rewrite to www
RewriteEngine On
RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]+$
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [L,R=301]
#remove html file extension
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html [NC,L]
#remove php file extension
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php [NC,L]
我该怎么做?
【问题讨论】:
-
请在您的问题中分享您的 htaccess 文件,谢谢。
标签: list .htaccess redirect mod-rewrite cpanel