Reputation:
I'm trying to make a .htaccess code for automatically rewrite rules for a directory.
In example:
URL: https://example.com/assets/test.png
Folder: /src/assets/test.png
or,
URL: https://example.com/js/test.js
Folder: /src/js/test.js
My htaccess file:
#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]
How can i make this?
Upvotes: 2
Views: 47
Reputation: 133760
Could you please do try following rule in your .htaccess file once. Please make sure you clear your browser cache before testing your URLs.
RewriteRule ([\w-]+)\.png/?$ src/assets/$1.js [R=301,NC,L]
Upvotes: 2