homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

redirect dynamic .php url to .html url

 12:28 pm on May 3, 2012 (gmt 0)

Hi, my site url is http://www.example.com/review.php?cid=14 and i want to redirect to http://www.example.com/review.html?cid=14.

There are hundreds of pages in my site like this which i want to redirect.

Please help for solution!


DarkEden Genesis

 2:04 pm on May 3, 2012 (gmt 0)

Hi gagan welcome.

First of all, you are looking for something called "mod rewrite".

You could make maybe better urls, like:

That would represents this -->> (example.com/review.php?cid=14)

Because changing review.php to review.html, KEEPING the same dynamic URL makes no sense.

Create a file named .htaccess and write this code inside it:
Options +FollowSymLinks
RewriteEngine On
RewriteRule reviews/([^/]+)/([^.]+) review.php?cid=$1&title=$2 [L]

Upload .htaccess to your root directory (with index.php).

After that you must change your PHP code to change the way it shows URLs.
If it actually does

so you must change to

I'm assuming your review has a title.

PS: Remember to check if your system acceppts mod rewrite.


 5:58 pm on May 3, 2012 (gmt 0)

This is exactly the right time for you to "go extensionless".

I'd use a URL like example.com/r14-the-page-name

Using a folder level for the id number is NOT appropriate.

These two recent threads may also be useful:


 9:02 am on May 4, 2012 (gmt 0)

Thanks for your help and direction.
Im new into this and dont have much knowledge about all this issues.
Here is the type of pages I have on my site:

example.com/review.php?cid=2&carpet=royal - 100 pages with different cid's and different carpet names
Want to change to example.com/carpet/royal

example.com/gas.php?gas=oxygen - 10 pages with different gases names.
Want to change to example.com/gas/oxygen

example.com/toxic_gases.php - 10 pages with different type of gases details
Want to change to example.com/toxic_gases.php

example.com/pages.html?action=Disclaimer - 10 pages with different type of actions.
Want to change to example.com/Disclaimer
Please guide me what changes i need to do for the same.
My site already having a .htaccess file and scripting is:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^http://localhost/
RewriteRule (.*) [localhost...] [R=301,L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*index\.html\ HTTP/
RewriteRule ^(.*)index\.html$ /$1 [R=301,L]
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example\.com
RewriteRule ^(.*)$ example.com/$1 [R=permanent,L]
RewriteEngine on
RewriteRule ^(.*)\.html$ $1.php
RewriteCond %{THE_REQUEST} ^.*/index.php
RewriteRule ^(.*)index.php$ example.com/$1 [R=301,L]
Please help me out of this..
Thanks & Regards,

RewriteEngine on
RewriteRule ^(.*)\.html$ $1.php

RewriteCond %{THE_REQUEST} ^.*/index.php
RewriteRule ^(.*)index.php$ http://www.example.com/$1 [R=301,L]

Please help me out of this..

Thanks & Regards,


 11:00 am on May 4, 2012 (gmt 0)

If the ID number is not going to appear in the new URLs, then you need to internally rewrite to a PHP script that then issues the redirect. This script will need to look in the database to see what the new URL will be.

Your current htaccess file has a large number of errors and inefficiencies. Luckiliy these are the same ones that are mentioned or discussed several times each week here.

Use http://www.example.com and http://example.com in this forum to prevent URL auto-linking.

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved