.htaccess 重写 URI 并替换其中的一部分
.htaccess rewrite URI w/ replace part of it
今天我有
https://www.teste.com/app/assets/folderX/file.pdf
但我需要重定向到:
https://assets.teste.com/folderX/file.pdf
我接近了解决方案:
RewriteCond %{REQUEST_URI} ^/app/assets/ [NC]
RewriteRule ^(.*)$ https://assets.teste.com/ [R=301,L,QSA,NC]
但是重写结束了:
https://assets.teste.com/app/assets/folderX/file.pdf
在 ReWrite 上,我需要从中删除子文件夹 /app/assets/....但我不知道如何。
经过一些尝试。可以使用:
RewriteCond %{REQUEST_URI} ^/app/assets/ [NC]
RewriteRule ^/?app/assets/(.*)$ https://assets.teste.com/ [R=301,L]
我用来测试的好工具是 https://htaccess.madewithlove.be/
您可以改用此规则:
RewriteCond %{HTTP_HOST} ^(?:www\.)?(teste\.com)$ [NC]
RewriteRule ^(app)/assets/(.*)$ https://.%1/ [R=301,L,NE,NC]
确保使用新浏览器测试此更改或完全清除旧浏览器缓存。
今天我有
https://www.teste.com/app/assets/folderX/file.pdf
但我需要重定向到:
https://assets.teste.com/folderX/file.pdf
我接近了解决方案:
RewriteCond %{REQUEST_URI} ^/app/assets/ [NC]
RewriteRule ^(.*)$ https://assets.teste.com/ [R=301,L,QSA,NC]
但是重写结束了:
https://assets.teste.com/app/assets/folderX/file.pdf
在 ReWrite 上,我需要从中删除子文件夹 /app/assets/....但我不知道如何。
经过一些尝试。可以使用:
RewriteCond %{REQUEST_URI} ^/app/assets/ [NC]
RewriteRule ^/?app/assets/(.*)$ https://assets.teste.com/ [R=301,L]
我用来测试的好工具是 https://htaccess.madewithlove.be/
您可以改用此规则:
RewriteCond %{HTTP_HOST} ^(?:www\.)?(teste\.com)$ [NC]
RewriteRule ^(app)/assets/(.*)$ https://.%1/ [R=301,L,NE,NC]
确保使用新浏览器测试此更改或完全清除旧浏览器缓存。