Forum Moderators: phranque
I have a a wordpress blog installed in http://www.example.com/blog/.
When I type http://www.example.com/blog/ OR http://example.com/blog/ in my firefox/IE7 address bar, the result will appear as http://www.example.com/blog/ . I believe this is what they call , a canonical form of URL (please correct me if I am wrong).
For my homepage, when I type http://example.com/ in my firefox/IE7 address bar, it will then appear as http://example.com/ . If I type http://www.example.com/ , it will then appear to be http://www.example.COM/ .
QUESTION 1 : That means my homepage is not redirecting the non-WWW into the www form of URL, and both format are accessible into my site, am I right on that?
QUESTION 2 : If question 1 is true, then my question is, are there any way to make my homepage URL automatically transform into the URL with WWW in front, whenever people type http://example.com/ in their address bar ?
QUESTION 3 : If question 2 is true, is that call a 301 redirect ?
QUESTION 4 : If question 3 is true, is there any code which is suitable for my case, to be used in my .htaccess file ?
Thanks in advance for all of your help in this wonderful forum :)
[edited by: jdMorgan at 3:18 pm (utc) on May 15, 2008]
[edit reason] Please use example.com [/edit]
2) Yes.
3) Yes.
4) Sure, do a search here on WebmasterWorld (link at top left of every page) for "canonical domain rewriterule rewritecond HTTP_HOST" -- This long search string should give you some fairly-specific results.
(I suspect that upon investigation, you'll find that /blog/.htaccess contains code similar to what you need, but since the code is in that subdirectory, it affects only that subdirectory and those below it. Either that, or your main .htaccess contains the code, but it is written to affect only the /blog/ subdirectory. Since the .htaccess code provided with blogs and forums is often badly-written, I suggest you do the above-recommended search anyway.)
Jim
RewriteEngine on
RewriteCond %{http_host} ^example.com [nc]
RewriteRule ^(.*)$ http://www.example.com/$1 [r=301,nc] I don't know that that is the best way to do it, but that's the dummied-down version that I use (I have multiple domains).
Edit: Also, I'd recommend you make a subdomain for a blog, such as blog.example.com. This means while you are in your code for your blog, / refers to blog.example.com (ie example.com/blog/), rather than example.com/. This is often how you would want it to work, so that's what I do. Also, once your subdomain is created, you won't want them visiting example.com/blog anymore, rather, you want that to be re-directed to blog.example.com. To do this:
.htaccess:
RewriteCond %{HTTP_HOST} !^blog.example.com [nc]
RewriteRule ^blog/ http://blog.example.com/$1 [r=301,nc] [edited by: Blue_Jeans at 4:49 pm (utc) on May 15, 2008]
For this moment, I won't be touching the blog directory, as I am not a very hosting-savvy person. I will leave it there, until I have the budget to ask someone else to create a sub-domain for me, and move all the things from my sub-directory to the blog sub-domain. Anyway, thanks for the method which you have introduced.
For my homepage now, I have done this redirection, and it works. Now, whenever I type http://example.com/ or http://www.example.com/ in my address bar, it will then redirect me to http://www.example.com/ .. Now all of my site is accessible only with the WWW being shown. A canonical form of URL , if I am not mistaken.
The code which I am using now, in my .htaccess file in my root folder, is this :
============================================================
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
============================================================
Hope that I am using the correct code.
Thanks again for your help.
It is possible that some starting URLs now see a double-redirect, or that internally rewritten URLs become exposed.
I'd still have the rule in the root, but I would add one more line to exclude it from operating on the /blog/ folder. I would rely on the code in the /blog/ folder to be the only code that is to have any influence there.
I am not a very tech savvy person, when it comes to web hosting stuff. So, I don't quite actually get what you meant by that.
However, currently this is the only code in my .htaccess file, which is under my /blog/ directory, please take a look and let me know what should I do about it .
============================================================
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /blog/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]
</IfModule>
# END WordPress
============================================================
Anyway, thanks for your reply, and thanks for your help.
Dealing with WordPress, you'll get hacked/exploited eventually. It happens all the time unless you keep up to date. This will happen if you are anywhere in the top 1000 results for "powered by WordPress" for any TLD search.
As this happens, and I'm talking from experience, and a bunch of spam links get hidden away in your template or posts, Google will drop you from it's index for at least 6 months. If it's a sub-domain, only the sub-domain will be penalized, but if its example.com/blog the entire site will be done.
This might seem a bit out there, but trust me, when it happens and it will, your much better off like this.
This has happened to my phpBB forums, to my SMF forums, a few times to my WordPress blog, and just a week ago I found a user with administrative privileges on WP when user registration was not even turned on!
[edited by: TowerOfPower at 7:11 pm (utc) on May 19, 2008]
Originally posted by TowerOfPower
This has happened to my phpBB forums, to my SMF forums, a few times to my WordPress blog, and just a week ago I found a user with administrative privileges on WP when user registration was not even turned on!
Hey TowerofPower, thanks for your reply , and thanks for the information given. Seriously, this is so scary !
May I ask you, which version of wordpress were you using, when you found out a user with administrative privileges on WP when user registration was not even turned on ? Version 2.5.1 ?
How did you get rid of that particular problem of WP ?
I will definitely change my blog directory to a sub-domain in the near future, but not now . Thanks again for the information given.
Appreciate that so much.
Though if you want to hear a real horror story listen to this...
Until very recently WordPress.org stated on the download page that all branches in the 2.0 and 2.2 [and maybe 2.3] releases where kept up to date with security patches.
Then one day they went 'whooops, even though we claimed 2.2/3 was maintained with security updates, it never really was as soon as 2.4 came out.' They did not even correct/announce this but on some obscure support thread.
People where running WP 2.2 for 6 months thinking it was patched and maintained when it was not.
This is how the OPEN-SOURCE free community works. LOL ... Couldn't complain that much. ;)
Personally, I think open-source and commercial software are two different worlds that meet two different needs. With of course a bit of an overlap.
If something like this happened at Microsoft... Customers would have been lost. Revenues would have declined. Heads would have rolled. Processes would have been updated. Meetings taken place.