Get domain name dynamically in htaccess file

Asked

Viewed 31 times

-2

I have a. htaccess file with several instructions. I would like to make it more dynamic, that is, make it more optimized for other sites without having to edit it.

Lines like the ones mentioned below refer to the domain name, I would like it to search for the domain name automatically, without the need to quote it.

RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ 
http://www.nomedodominio.com.br/diretorio/administrador/$1 
[R=301,L]

and

ErrorDocument 404 http://www.nomedodominio.com.br/diretorio/administrador/

Note: I need to keep the path after the domain name: /directory/administrator/.

Thanks in advance.

  • 2

    We have an absurd amount of posts about htaccess on the site, practically covering almost all common situations, it would be good a researched. This is what you want is normal, what is not normal is the domain to be "hardcoded" as in your example (to start the conversation, the lines would not need to have the domain referred).

1 answer

3


Just remove the domain, the rewriterule will only need if you really want to change domino, the same goes for the ErrorDocument, in case just do this:

RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ /diretorio/administrador/$1 [R=301,L]

ErrorDocument 404 /diretorio/administrador/

Remember, the bar in front / indicates the root folder in redirects and in ErrorDocument indicates the file location in your VirtualHost

  • Thank you very much!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.