I want to replace my.example.com/newsletter.php or example.com/newsletter.php to be example.com/newsletter/
I tried this:
RewriteEngine On
RewriteRule ^([a-z]+)$ /$1.php [L]
and what if I want http://example.com/communities/index.php?sub_id=1
to be a specific name like http://example.com/communities/Bridlewood/
possible?
The other answers are right about the leading slash, and you should catch the possibility of a trailing slash (bearing in mind that ‘$’ marks the end of a string .
Try something like this:
RewriteBase / RewriteCond %{SCRIPT_FILENAME} !-f RewriteCond %{SCRIPT_FILENAME} !-d RewriteRule ^([a-z-]+)/?$ /$1.php [QSA,NC,L]Note: The
QSAflag stands for ‘query string append’ and will pass any url query on to the relevant page.hth
EDIT: For URL’s that contain characters other than lower case alpha’s you should change the range group, use a case-insensitive switch or simply use
(.*)as per other peoples examples!