This is exactly what I am trying related to the htaccess:

  • Pressure take away the www in the url
  • Have the ability to use to get at, and pressure the final slash even when it isn't added through the user. Therefore if i write it will likely be transformed into
  • Also translate to Also into

The htaccess code should not need to retain the domain it will likely be utilized on.

I have been looking for something similar to this around the internet for age range, however i only find each part and they are not effective together.

Can anybody assist me to with this particular?

Just written these off the top my mind, they may have errors ... but think the jist is appropriate. Comment if you will find errors and I'll take a look.

For that www bit:

RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

The website bit:

RewriteRule ^([^/]*)$ /$1/ [R=301,L]
RewriteRule ^([^/]*/)$ /$1.php


RewriteRule ^download/(.+)$ /download.php?file=$1


RewriteRule ^news/article/([0-9]+)$ /news.php?article=$1

Ok, here's my try. Observe that the Apache manual is very good. I vary from benlumley around the "site" portion. Also, you might want to replace ([0-9]+) with simply (.+) in case your news article names aren't all number.

# Ensure that rewriting is enabled
RewriteEngine on

# First strip the www as benlumley did
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

# Then convert /site to /site/, reflecting the change in the address bar
RewriteRule ^([^/.]+)$ /$1/ [R=301,L]
# Finally map /site/ to /site.php
RewriteRule ^([^/.]+)/$ /$1.php

# Finally, fix download and news as benlumley did
RewriteRule ^download/(.+)$ /download.php?file=$1
RewriteRule ^news/article/([0-9]+)$ /news.php?article=$1

EDIT: Fixed copy/paste error for that "strip www" part.

NOTE: Any <link href="..."> or <script src="..."> tags you have will have to be specified as absolute pathways since you have effectively transformed your directory the page seems to become offered from.

E.g. think about the following line out of your blog.php:

<link rel="stylesheet" type="text/css" href="style.css">

Formerly the browser saw http://site/blog.php and therefore attempted to retrieve http://site/style.css, which labored.

Since the browser rather sees http://site/blog/ the relative URL above is construed as http://site/blog/style.css, which doesn't exist. As a result, the href must be transformed as:

<link rel="stylesheet" type="text/css" href="/style.css">