How to hide a subfolder in url rewriting

流过昼夜 提交于 2019-12-11 10:16:29

问题


My site is : www.mysite.com/subfolder/login/index.php

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]

--but the problem is that then it can't use or access the CSS file (style.css) from the login folder.


回答1:


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

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]

You can see more examples and ways of rewriting here: https://wiki.apache.org/httpd/Rewrite




回答2:


Add Another rule for css, or use absolute CSS path e.g.:

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



回答3:


The title does not seem to match the question at the end of your description, but to answer the latter: If you have a problem with your assets (images, css, external javascript, etc.) after url rewriting, use absolute paths, for example:

/subfolder/login/style.css

instead of something like:

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


来源:https://stackoverflow.com/questions/23200161/how-to-hide-a-subfolder-in-url-rewriting

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!