简体   繁体   English

如何使用htacess重写url

[英]how to rewrite url using htacess

https://example.com/folder/subfolder/demo1 https://example.com/folder/subfolder/demo2 https://example.com/folder/subfolder/demo1 https://example.com/folder/subfolder/demo2

i want to open the above urls as https://example.com/demo1 https://example.com/demo2我想将上述网址打开为https://example.com/demo1 https://example.com/demo2

if i open https://example.com/folder/subfolder/demo1 it should open https://example.com/demo1 it should not show folder/subfolder in the address bar.如果我打开https://example.com/folder/subfolder/demo1它应该打开https://example.com/demo1它不应该在地址栏中显示文件夹/子文件夹 it should automatically show and open the desired custom link.它应该自动显示并打开所需的自定义链接。 it should only rewrite not redirect.它应该只重写而不是重定向。 please help请帮忙

You could try to write the rules like this :您可以尝试编写这样的规则:

RewriteEngine on
RewriteCond %{HTTPS} off 
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^folder/subfolder/(.*)$ ./$1 [L,QSA]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM