如何在url重写中隐藏子文件夹
问题描述:
我的网站是:www.mysite.com/subfolder/login/index.php
My site is : www.mysite.com/subfolder/login/index.php
我希望网址只是 www .mysite.com /登录/ index.php的
。我尝试修改根文件夹中的.htaccess文件,如下所示:
I want the URL there to just be www.mysite.com/login/index.php
. I tried modifying the .htaccess file in the root folder as follows:
RewriteRule ^login\/index\.php$ /subfolder/login/index.php [L]
- 但问题在于它可以从登录文件夹中使用或访问CSS文件(style.css)。
--but the problem is that then it can't use or access the CSS file (style.css) from the login folder.
答
# fix js/images/css
RewriteRule ^.+?/((img|css|js)/.+)$ /subfolder/login/$1 [L,NC]
尝试在 htaccess
中添加它作为您的第一条规则。或者您可以使用
Try adding this as your first rule in htaccess
. Or you can use
# fix js/images/css
RewriteRule ^.+?/((img|css|js)/.+)$ http://www.yourdomain.com/subfolder/login/$1 [L,NC]
您可以在此处看到更多示例和重写方式: https://wiki.apache .org / httpd /重写
You can see more examples and ways of rewriting here: https://wiki.apache.org/httpd/Rewrite