Tag Info

Hot answers tagged

7

Empty Virtual Host With virtual hosting, all traffic is routed to an IP address and then Apache matches the hostname. When virtual hosting using NameVirtualHost is enabled, the site that responds to the IP address is the first one listed in the Apache configuration file. So you can use a null virtualhost: <VirtualHost 192.168.1.1:80> ...


2

For your first two rewrites (non-www → www, http → https), the following rule should work: RewriteEngine On RewriteCond %{HTTPS} off [OR] RewriteCond %{HTTP_HOST} !=www.example.com [NC] RewriteRule ^(.*) https://www.example.com/$1 [NS,L,R=permanent] Just replace www.example.com with the actual canonical hostname of your site. As for your third ...


2

You can't check for the query string using the RewriteRule pattern (the query string is stripped before pattern matching, as is the hostname, etc). So, the rules you stated above simply won't match and you'll get a 404. However, you can use the RewriteCond directive to check the query string: For example: domain.tld/en/abc.php?foo to ...


2

You could simply redirect the user to the named host: # Uncomment the line below if not previously added in the file # RewriteEngine On # Rule to redirect to the named host # Replace [xx.xx.xx.xx] woth your host's IP address # Replace [yourdomain.com] with your host's proper URL RewriteCond %{HTTP_HOST} ^xx\.xx\.xx\.xx$ RewriteRule (.*) ...


1

The use of a rewrite condition along with a rule to map transparently to the subdirectory should work. RewriteCond %{HTTP_HOST} ^abc\.mybiz\.domain\.com$ [NC] RewriteCond %{REQUEST_URI} ^(/|.*\.html)$ [NC] RewriteRule ^/(.*)$ /abc/$1 [L] Now when a request for http://abc.mybiz.domain.com/ or http://abc.mybiz.domain.com/index.html is made it will be pulled ...


1

I had to ask this question myself. It is surprisingly tricky to do. Olaf Dietsche provided the solution of using an environment variable: RewriteRule ^contact$ contact.php [L,E=CLEAN_CONTACT_URL:1] RewriteCond %{ENV:REDIRECT_CLEAN_CONTACT_URL} !1 RewriteRule ^contact\.php$ /contact [R=301,L] That way the redirect only gets executed when contact.php is ...


1

Yes you would. You are telling Apache to take any reference to contact and rewrite the URI to contact.php then telling Apache to take any contact.php reference and change it to /contact which gets captured again by the first rule. Here is what you are missing. For each rewrite or redirect, Apache makes the change then starts the whole matching process over ...



Only top voted, non community-wiki answers of a minimum length are eligible