Welcome to WebmasterWorld Guest from 18.204.48.199

Forum Moderators: phranque

Message Too Old, No Replies

URL’s re-write

     
7:32 am on Jun 7, 2011 (gmt 0)

Junior Member from IN 

joined:Feb 24, 2011
posts: 83
votes: 0


Hi There,
One of my client wants to re-write the URL's structure of the website i'm putting one example of same: - eg. www.example.com/abc-89.html Into www.example.com/abc

They want change structure of URL's And remove URL's extensions(.html or .php) as well...

Is it fine..
Kindly brief me on this..

Thanks
8:00 am on June 7, 2011 (gmt 0)

Junior Member

10+ Year Member

joined:June 26, 2008
posts:178
votes: 0


The way you do this is in the .htaccess file. The way I would remove my PHP extensions would be like this...

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ $1.php [L,QSA]

Hope that helps, somewhat.
8:35 am on June 7, 2011 (gmt 0)

Senior Member

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

joined:July 3, 2002
posts:18903
votes: 0


There are many previous threads with this information.

You must first change the link on your page to point to the correct URLs.

Next install a rewrite. While the example posted above would work it is very inefficient because every request hitting your server invokes two very slow disk reads. Remove the two RewriteCond lines and change the ^(.*)$ pattern to ^([^/.]+)$ or similar so it simply tests for "extensionless" requests.

A fatal flaw of the previous code is that a request for the URL
example.com/
is mapped to the file
/.php


The final part of the puzzle is to redirect client .html and .php URL requests to the extensionless URL.

However, for the example in the original post this solution cannot be directly used here because there is no way for mod_rewrite to know to add or remove the "-89" part. You are better off retaining the ID number in the new URLs, otherwise you will have to have a database to look up the URL mappings.
8:53 am on June 7, 2011 (gmt 0)

Junior Member from IN 

joined:Feb 24, 2011
posts: 83
votes: 0


Thanks Guys,

But; is it effect on current ranking & page rank?
4:16 pm on June 7, 2011 (gmt 0)

Senior Member

WebmasterWorld Senior Member rocknbil is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Nov 28, 2004
posts:7999
votes: 0


You won't lose indexing with a proper 301 . . . .

rewriteRule ^abc-89.html$ /abc [R=301,L]

... but you'd have to do that for every URL, impractical on a large site.

@g1smd: awesome display of restraint. :-)
7:52 am on June 8, 2011 (gmt 0)

Junior Member

10+ Year Member

joined:June 26, 2008
posts:178
votes: 0


I tried my best. ;) I'm really trying to sharpen my htaccess skills, so forvive my poor code. This has worked for me on several occasions, I thought it would be okay.

What would you recommend g1smd?

RewriteEngine On
RewriteRule ^([^/.]+)$ $1.php [L,QSA]
12:23 pm on June 8, 2011 (gmt 0)

Junior Member from IN 

joined:Feb 24, 2011
posts: 83
votes: 0


Thanks..
11:48 pm on June 8, 2011 (gmt 0)

Senior Member

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

joined:July 3, 2002
posts:18903
votes: 0


I'd rewrite to a PHP script and have all the logic in that PHP script (with data in an array for a small site, or in a database for a large site). The PHP script would send the correct headers back.

The array method was discussed about a month ago, with code included.
7:42 am on June 9, 2011 (gmt 0)

Junior Member

10+ Year Member

joined:June 26, 2008
posts:178
votes: 0


Cool, cheers!
8:46 pm on June 10, 2011 (gmt 0)

Senior Member

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

joined:Oct 25, 2005
posts:3598
votes: 53


But; is it effect on current ranking & page rank
The answer to both of these is yes. Changing the url structure will effect both your ranking and PR. Both will probably come back after Google sorts it all out. A time is a complete guess.