Welcome to WebmasterWorld Guest from 54.167.58.159

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

redirect dynamic .php url to .html url

redirect

     

gagankkharbanda

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:

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

Why?
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
review.php?cid=$id

so you must change to
reviews/$id/$title


I'm assuming your review has a title.


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

g1smd

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

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



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:
[webmasterworld.com...]
[webmasterworld.com...]

gagankkharbanda

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



Hi,
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:

SetEnv DEFAULT_PHP_VERSION 5.3
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,
Gagan

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,
Gagan

g1smd

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

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



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.