htaccess mask for my url

2019-07-26 04:57发布

问题:

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 (/).