htaccess mask for my url

一曲冷凌霜 提交于 2019-12-11 13:33:22

问题


I'm trying to mask a part of my url using .htaccess but I'm having several issues

my url is http://ristorantitalianetwork.com/ristorantitalianetwork.com/admin/

I'd like to remove the duplicate ristorantitalianetwork.com, so I'd like that my url will be like

http://ristorantitalianetwork.com/admin/

I've used

RewriteRule ^ristorantitalianetwork.com/([^/]*)$ ?q=$1 [L] 

but it doesn't work

Could you please help me to figure out how to solve this problem?

Thanks a lot

Best regards


回答1:


You really need

RewriteRule ^/admin$ /ristorantitalianetwork.com/admin [L] 

Bear in mind that the URL you should expose to users is http://ristorantitalianetwork.com/admin/ which will then internally get converted (rewritten) to http://ristorantitalianetwork.com/ristorantitalianetwork.com/admin/.

It is not the other way round as many believe.




回答2:


You almost did it! But...

In your question, your rewriterule says that it is applied on URLs that don't end with a slash (/). And you say you want to rewrite some URLs... and give URLs examples with a slash (/).

If you need to do a real redirect (i.e. the URL in the browser changes):, here's the good rewriterule:

RewriteRule ^ristorantitalianetwork\.com/([^/]*)/$ /$1 [QSA,R=301,L]

If you need to do only internal redirect:

RewriteRule ^ristorantitalianetwork\.com/([^/]*)/$ /$1 [QSA,L]

Keep in mind that the URL must end with a slash (/).



来源:https://stackoverflow.com/questions/8615812/htaccess-mask-for-my-url

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