Keep Server Online
If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.
or
A donation makes a contribution towards the costs, the time and effort that's going in this site and building.
Thank You! Steffen
Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
| |
|
Topic: Need confirmation of rewrite code |
|
Author |
|
joncmac
Joined: 27 Feb 2013 Posts: 1 Location: USA, Woburn
|
Posted: Wed 27 Feb '13 21:51 Post subject: Need confirmation of rewrite code |
|
|
Apache version 2.2.17
Hi,
First time posting here. My webhost provider installed code to my HTACCESS file for a canonical 301 redirect to www. I have never encountered this particular code before, I have researched it online and can't find anyone else who has used it. I would like feedback on whether this will work.
Thank you
Code: | RewriteEngine on
# Safe force www prefix (won't do weird redirects with addon/subdomains)
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
|
|
|
Back to top |
|
James Blond Moderator
Joined: 19 Jan 2006 Posts: 7371 Location: Germany, Next to Hamburg
|
Posted: Mon 04 Mar '13 16:48 Post subject: |
|
|
Code: |
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
|
This ia how I force www. |
|
Back to top |
|
Qmpeltaty
Joined: 06 Feb 2008 Posts: 182 Location: Poland
|
Posted: Tue 12 Mar '13 12:47 Post subject: |
|
|
Both of you are wasting server's performance.
http://httpd.apache.org/docs/2.2/rewrite/avoid.html
Quote: | mod_rewrite should be considered a last resort, when other alternatives are found wanting. Using it when there are simpler alternatives leads to configurations which are confusing, fragile, and hard to maintain. Understanding what other alternatives are available is a very important step towards mod_rewrite mastery. |
Getting back to main problem, the www rewrite i made is :
Code: |
<VirtualHost IP:80>
ServerName mydomain.com
Redirect permanent / http://www.mydomain.com/
</VirtualHost>
<VirtualHost IP:80>
ServerName www.mydomain.com
DocumentRoot "C:/Apache2.4.3-x64/htdocs"
</VirtualHost> |
|
|
Back to top |
|
|
|
|
|
|