You'll need two Rewriterules one for the index and hostname redirect and one for the hostname redirect.
The code for this has been published many times before. Check through these:
Use "example.com" in all forum code examples. This suppresses the forum auto-linking function.
phranque, you out there? A while back someone had an issue with one of those URL-checking tools. Turns out it wasn't returning the correct results for one category of variation. (Don't remember what, and it doesn't really matter, but it was something utterly basic like with/without www or the explicit /index.html name.) So either they thought they had a problem when they didn't really, or they did have a problem and the tool wasn't helping.
3 and 4 should both redirect to either 1 or 2. So should anything else in index.html; it's typically your second-to-last redirect.
Either 1 or 2 (your choice, so long as you're consistent) should redirect to the other. This is typically your last and most general redirect.
This is assuming for the sake of discussion that "index.html" is the actual name of your physical index file. If it's called something else, such as index.php, it's again your choice whether you want to redirect at all, or let bad requests pick up a 404.
But what I really want to know is whether it's a redirect issue or a tool issue. If you use something like LiveHeaders (Firefox, there are probably equivalents for other browsers) do all four URLs report 301 responses? If so, what are they all getting redirected to? 1 and 2 can't redirect to each other, or you'd be getting an infinite loop.
Thanks lucy24 for taking time to answer my query.
|But what I really want to know is whether it's a redirect issue or a tool issue. If you use something like LiveHeaders (Firefox, there are probably equivalents for other browsers) do all four URLs report 301 responses? If so, what are they all getting redirected to? 1 and 2 can't redirect to each other, or you'd be getting an infinite loop. |
I don't think there's any problem with the Tools because I checked for my other sites and it's fine. Yes 1 and 2 can't redirect each other. But it's showing 301 for all the urls.
Btw one thing I found in htaccess file that there's no redirection code for domain but for blog of the same [domain.com/blog.html].
Do I need to write 301 lines there ?
Thanks g1smd for your help.
|Do I need to write 301 lines there ? |
Heavens, no, if there are that many special cases you're better off rewriting to a--
Whoops! That was actually an old joke of jdMorgan's. I've paraphrased.
Does your htaccess file contain RewriteRules? I'm guessing yes, if you're using any kind of CMS for your blog.
Another possibility is that your host is redirecting. Some offer this as an option for domain names. If so, the redirect won't be visible in your local htaccess files because it's done at the config level. Check your hosting control panel; name and details depend on host, but there's generally something.
Once you start making your own RewriteRules, turn off any host-level options and shift them to your own htaccess instead. Otherwise you risk some requests getting redirected twice, because the host's generic rule will kick in before your specific ones.
Sorry guys I forget to mention a very important point that site is in Wordpress.
Will that make any difference?
The important thing about WordPress-- or any other major CMS-- is that it comes with its own htaccess file, mainly involving a lot of rewriting. So if you're making changes of your own, you have to be VERY careful to put your new rules in the right places, where they won't conflict with the existing rules.
I am still unable to solve !
Can anyone tell me precisely how to solve this problem ?
I shall be thankful if you explain stepwise.
Let's see what code you already have.
This question has been covered more than 500 times since this forum started so there's no shortage of previous examples.
This is the Website Technology forum ;)
Sunny, you probably do want the Apache subforum. It's right next door. The same people will see your question, but you can start by looking at some of the earlier posts. Look especially at anything involving WordPress or some other CMS that has a ready-made htaccess.
while you're under the hood you might want to look at this - How To Speed Up WordPress: