Hello, I have a website which developed using PHP. I wish to rewrite the URL for better SEO. Currently the url has following structure http://www.domainname.com/_Site/about.php http://www.domainname.com/_Site/contact.php I wish to rewrite the above URLs into http://www.domainname.com/about http://www.domainname.com/contact I can't alter the folder structure. Please suggest a solution. What all things I need to put in .htaccess file. Thanks SpiceMint
RewriteEngine on RewriteRule about _Site/about.php [L] RewriteRule contact _Site/contact.php [L] and so on
Thanks for your help. Rewriting is worked fine but CSS and images in those pages were not displayed correctly. Any clue? Also can you please provide a generic rewriting rule for all pages under '_Site' folder? Thanks SpiceMint
it isn't possible to do it generic... about images, where you got them? If in _Site/images/something.jpg, & CSS in _Site/css/style.css try this RewriteEngine on RewriteRule (.*)\.css _Site/css/$1.css [L] RewriteRule (.*)\.jpg _Site/images/$1.jpg [L] RewriteRule (.*)\.png _Site/images/$1.png [L] RewriteRule (.*)\.gif _Site/images/$1.gif [L] # any other formats of images RewriteRule about _Site/about.php [L] RewriteRule contact _Site/contact.php [L]
Thanks again for your support. It's working fine. But I need little clarification. If I enter http://www.domainname.com/about, it will goto about page without any problems. Bu if I enter something like "about1", "abouthghgh" etc after domain name, it will also goto about page. Is there any way to strictly specify "about" is the only word for correct redirection. This problem persist in all other pages. Thanks SpiceMint
i'm borrowing your code G3n3s!s you can optimize here: RewriteEngine on RewriteRule ^(.*)\.css$ _Site/css/$1.css [L] RewriteRule (.*)\.(jpg|jpeg|png|gif|bmp)$ _Site/images/$1.$2 [L] # any other formats of images RewriteRule ^(about|contact)$ _Site/$1.php [QSA,L]
yup, that's faster for OP, if you want to do it stricly, do it as gap said or this way ($ = end of line (end of link))