Forum Moderators: phranque

Message Too Old, No Replies

Need small.htaccess help

         

iCyborg

6:28 am on Mar 24, 2009 (gmt 0)

10+ Year Member



I have 2 url's like this -
http://www.example.com/news/pages.php?nID=16&pID=812
http://www.example.com/news/pages.php?nID=16&pID=822

How to make them like this using .htaccess

http://www.example.com/news/first-news-item
http://www.example.com/news/second-news-item

Thanks

g1smd

8:52 am on Mar 24, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



What code have you tried so far?

Luckily there have been at least half a dozen similar discussions for this type of problem so far this month, which you can raid for example code.

You'll need to link to the new format URLs from within your pages as it is links that define URLs.

You'll need a rewrite to connect your URL request to the true internal filepath for the content or to a script that can look up the associations in the database.

Finally, you'll need a script that when asked for the old format URLs, sends out a 301 redirect to the new format URL so that the content can no longer be indexed as duplicates at the old URL.

This is not a simple job, because the association between /news/pages.php?nID=16&pID=822 (in numbers) and /news/second-news-item (in words, perhaps the title of the article?) cannot be gleaned within .htaccess nor programmed in advance.

You will have to go to your database to look up the association of URL and database entry in a new table that you have to add to your database - unless the second-news-item is actually the 'title' for the article, and is already in the existing database.

IF you simply wanted to change from /news/pages.php?nID=16&pID=812 to /news/16/812 then that would be very easy to achieve in .htaccess with less than a dozen lines of code, including canonicalisation fixes, because there is a very simple relationship between the old and the new URL.

iCyborg

11:49 am on Mar 25, 2009 (gmt 0)

10+ Year Member



well I am really not able to think of anything as I suck in .htaccess. Actually I am not concerned about association or anything, I just have 2 urls, with dynamic links (they are not actually its just the query string is such), so I need to make the link static and search engine friendly.

g1smd

11:58 am on Mar 25, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



If you have two just URLs, then there are a myriad of choices, and can just manually add those two redirects to your.htaccess file.

The stuff about association is important. If you have a million pages, you do not want a URL structure such that you have to manually add one million redirects and one million rewrites into your .htaccess file.

You would need a simple system such that two lines of code, with a REGEX pattern match, can be used for all one million pages. It would map URL requests for example.com/news/23/543 to the internal filepath /index.php?cat=news&id=23&item=543 and so on. There would also be a redirect such that direct client requests for /index.php?cat=news&id=23&item=543 (and with those parameters in any other order) would be redirected to example.com/news/23/543 as well. Your internal links would also need to point to example.com/news/23/543 too.

With that idea in mind, you would be able to set up the new URL system in mere minutes, and not have to touch it again when adding new content.

iCyborg

12:23 pm on Mar 25, 2009 (gmt 0)

10+ Year Member



Hi g1smd,can you tell me what should be the code then in .htaccess ? :)