This is what I’m trying to do with the htaccess:
- Force remove the www from the url
- Be able to use http://website.com/site/ to get to http://website.com/site.php, and force the last slash even if it’s not added by the user. So if i write http://website.com/site it will be converted to http://website.com/site/
- Also translate http://website.com/download.php?=file.exe to http://website.com/download/file.exe. Also http://website.com/news.php?article=43532 into http://website.com/news/article/43532
The htaccess code should not have to contain the domain it’s going to be used on.
I’ve been trying to find something like this on the net for ages, but I only find each part and they don’t work together.
Can anyone help me with this?
Ok, here’s my try. Note that the Apache manual is quite good. I differ from benlumley on the ‘site’ portion. Also, you may want to replace
([0-9]+)with simply(.+)if your news article names are not all numeric.EDIT: Fixed copy/paste error for the ‘strip www’ part.
NOTE: Any
<link href='...'>or<script src='...'>tags that you have will now need to be specified as absolute paths because you have effectively changed the directory that the page appears to be served from.E.g. consider the following line from your blog.php:
Previously the browser saw http://site/blog.php and thus tried to retrieve http://site/style.css, which worked.
Now that the browser instead sees http://site/blog/ the relative URL above is interpreted as http://site/blog/style.css, which does not exist. As such, the href needs to be changed as: