簡體   English   中英

如何在URL重寫中隱藏子文件夾

[英]How to hide a subfolder in url rewriting

我的網站是:www.mysite.com/subfolder/login/index.php

我希望那里的URL只是www.mysite.com/login/index.php 我嘗試如下修改根文件夾中的.htaccess文件:

RewriteRule ^login\/index\.php$ /subfolder/login/index.php [L]

-但問題在於,它無法使用或訪問登錄文件夾中的CSS文件(style.css)。

# fix js/images/css
RewriteRule ^.+?/((img|css|js)/.+)$ /subfolder/login/$1 [L,NC]

嘗試將其添加為htaccess的第一條規則。 或者你可以使用

# fix js/images/css
RewriteRule ^.+?/((img|css|js)/.+)$ http://www.yourdomain.com/subfolder/login/$1 [L,NC]

您可以在此處查看更多示例和重寫方式: https : //wiki.apache.org/httpd/Rewrite

為CSS添加另一個規則,或使用絕對CSS路徑,例如:

RewriteRule login\(.*)\.css /subfolder/login/$1.css [L]

標題似乎與描述末尾的問題不符,但可以回答后者:如果在重寫URL后資產(圖像,CSS,外部javascript等)有問題,請使用絕對路徑例:

/subfolder/login/style.css

而不是這樣的:

../style.css    /* this will probably not work when rewriting urls */

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM