Forum Moderators: phranque

Message Too Old, No Replies

ReWriting PHP Generated URLs

         

jacannon2

4:04 pm on Sep 9, 2008 (gmt 0)

10+ Year Member



I'm new to ReWriting in .htaccess

Just read up on the subject, but am still unclear on how to do this.

I have this URL...

www.example.com/category.php?currentSection=1

And I want to rewrite it to this...

www.example.com/browse/catone

As well as other URLs...

www.example.com/category.php?currentSection=2
www.example.com/browse/cattwo

www.example.com/category.php?currentSection=3
www.example.com/browse/catthree

How do I do this?

[edited by: jdMorgan at 4:14 pm (utc) on Sep. 9, 2008]
[edit reason] Use example.com please. [/edit]

jdMorgan

4:13 pm on Sep 9, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You cannot rewrite the URLs that appear on your pages. You'll have to modify your PHP script to produce static-looking SE-friendly links, since those links on your pages define the URLs.

Then you can use mod_rewrite to "re-connect" incoming client requests for those static URLs to your script, by translating them back into your original dynamic script filepath+query string format.

As an optional third step, you can redirect (only) direct client requests for the "old" dynamic URLs to the "new" static URLs, to speed up search engine re-indexing and to recover/preserve the pre-existing PageRank of those old URLs.

See this thread [webmasterworld.com] in our forum library for details, explanations, and instructions.

Jim

jdMorgan

4:15 pm on Sep 9, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Also, it will vastly simplify your code if you use "cat1," "cat2," "cat3," instead of "catone," "cattwo," "catthree."

Jim

jacannon2

5:38 pm on Sep 9, 2008 (gmt 0)

10+ Year Member



"You cannot rewrite the URLs that appear on your pages. You'll have to modify your PHP script to produce static-looking SE-friendly links, since those links on your pages define the URLs."

I understand this.

"Then you can use mod_rewrite to "re-connect" incoming client requests for those static URLs to your script, by translating them back into your original dynamic script filepath+query string format."

I understand this as well.

"As an optional third step, you can redirect (only) direct client requests for the "old" dynamic URLs to the "new" static URLs, to speed up search engine re-indexing and to recover/preserve the pre-existing PageRank of those old URLs."

That's something I read about too.

"See this thread in our forum library for details, explanations, and instructions. "

Looked over it and it's exactly what I've been reading, I still can't find something that specifically addresses my issue, thus the reason I posted my question here.

"Also, it will vastly simplify your code if you use "cat1," "cat2," "cat3," instead of "catone," "cattwo," "catthree." "

Good point. I used these for examples only. The actual names are things like "beauty", "health" and the like, not "catone" and "cattwo".

I just need the code that will tell the server to translate the numbers in the current urls (when typed into the address bar, not every url in the page) to words and then rewrite the url to http://www.example.com/browse/nameofcategory

I get the logic behind it, I just can't translate my logic into something the .htaccess file will read.

jdMorgan

6:23 pm on Sep 9, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you "translate" from numbers to words, then you will likely need a specific rule for each possible case, leading to a large and unmanageable files.

Alternately, if you have server-config file access (httpd.conf, conf.d, etc., you can define a RewriteMap. The RewriteMap can either use a lookup table, or it can call a small script (i.e. PERL) to open your database, read in the entry for the id number, retrieve the "word", and pass that back to mod_rewrite. This latter approach, while more complex, results in easier management, since all updates or additions can be done using your usual database-management tools -- The data is centralized in one place.

Jim

jacannon2

7:12 pm on Sep 9, 2008 (gmt 0)

10+ Year Member



I like the logic of the second choice, but again this is a language I don't speak. I do have server-config file access.

What's my next step?