.htaccess - partial success, now end of wits :(

The site in development: http://kauaiwedpro.com/rebuild (I’m not responsible for the site [php, sql, etc.], I was ONLY asked to do the mod_rewrite)

The mod_rewrite tasks:

1:

http://www.kauaiwedpro.com/rebuild/wedding-coordinators
instead of
http://kauaiwedpro.com/rebuild/category.php?cat_id=1

–> I solved that via

RewriteRule ^([a-zA-Z-0-9]+)$ category.php?cat_id=$1

But where I am faltering is:
2:

[http://www.kauaiwedpro.com/rebuild/wedding-coordinators/a-simple-marriage
instead of
http://kauaiwedpro.com/rebuild/listing.php?cat_id=1&listing_id=1

I tried all sorts of rewrites, and the closest I get is

RewriteRule ^([a-zA-Z-0-9]+)/([a-zA-Z-0-9]+)$ listing.php?listing_id=$1&cat_id=$2

but nothing is working :frowning:

It seems I would first have to define for example http://kauaiwedpro.com/rebuild/listing.php?listing_id=1&cat_id=wedding-coordinators , but I am faltering even there (sigh).

Would any of you pros please point me into the right direction (and if you feel like it explain where I’m thinking wrong).

Thank you,
Lee

aha, one step further: the content on the right gets displayed now - so only the menu on the left is now missing

http://www.kauaiwedpro.com/rebuild/wedding-coordinators/a-simple-marriage

RewriteRule ^([a-zA-Z-0-9]+)/([a-zA-Z-0-9]+)$ listing.php?cat_id=$1&listing_id=$2

gosh, this 30 mins edit limit is very annoying - I’m not a little kid, admins …

Anyway, forgot to mention that I did add <base href=“http://kauaiwedpro.com/rebuild/category.php” /> and <base href=“http://kauaiwedpro.com/rebuild/listing.php” /> into the respective files …

Lee,

The problem is that there is no apparent mapping between wedding-coordinators and cat_id’s value of 1. Actually, I describe this in the tutorial Article linked in my signature … as well as a way around that (changing the links and the PHP code handling the links).

Whoops! That’s not your job, though, is it? Look into a RewriteMap (which requires access to the server’s conf file) OR create a handler.php script which you can use to map from “wedding-coordinators” to “1”. Yes, that’s in the tutorial, too. For that matter, I’m sure that the sticky created from the tutorial probably has both solutions to the problem, too. :nono:

Regards,

DK

thanks for your reply. I had pretty much realized that there is a missing piece.

David, I have been studying your topic http://datakoncepts.com/seo (amongst others) up and down many times, with all text displayed. That’s how above strings came into existence. I read through it again just now and even searched for ‘handler’ - the only mention of ‘handler’ is re. if mod_rewrite listed or not …

Please note that I’m still learning. What’s obvious to you with all your experience might totally not be obvious to others …

Re. ‘Look into a RewriteMap’: correct, I don’t have access, but I will (have to) forward your finding (to both others involved). The only instance of ‘RewriteMap’ is in this paragraph:

There have been many questions about how to use a database to redirect from a title (or other field) to an ID. Unless you have access to your httpd.conf (in order to create a RewriteMap application), forget about using a database for your redirections. Instead, make the field of choice unique and use that field to create your links.

This is nothing I can forward, because I would (reasonably) be told that a mention of ‘many questions’ does not help, and that instead we need an answer … :wink:

I would be greatly appreciated if you could point me to the answers and solutions re. ‘RewriteMap’ (and ideally even include a link in that paragraph of your Apache’s mod_rewrite topic to the thread where RewriteMap solutions are listed. In that regard even a mention of ‘handler.php’ + link to such treatise could only be beneficial.)

Thank you,
Lee

PS:

I’m sure that the sticky created from the tutorial probably has both solutions to the problem, too.
That’s an oxymoron - EITHER sure OR probably … :wink:

Lee,

Ha! Too true!

Okay, one option is to change the cat_id to some other UNIQUE field. I’ve done this for a client (http://wilderness-wally.com) where I allow him to use his article titles (with the spaces changed to _'s and a few other non-alphanumeric characters allowed) as the URI rather than the article’s id (key field). The SINGLE file which presents all the pages on his site will revert to the Welcome (Home) page if the title’s been mis-typed by some visitor. Because the TOC on the left is generated from the database contents, it should always provide a valid link. That’s not what you asked for, though, is it?

Okay, the “poor man’s” RewriteMap could be implemented with a combination of mod_rewrite code and a handler file. The process (within mod_rewrite) would be to use a RewriteCond to test for the existence of a (PHP) file and redirect to the handler (with a query string containing the {REQUEST_URI} string) if it’s not found. The handler file would then fetch the uri value from the $_GET array and search the database for the cat_id and listing_id values which are associated with the uri value (for your cat_id and listing_id case, explode() on ‘/’ and assign to the correct key). With the values returned from the database, you can then execute a header(‘Location:…’) relocation - just remember to send the 200 code before the Location if the values are found.

Give that a try then post your code if you have any problems. Okay, to help others who may be looking at this thread, post anyway, if you please. I’ll check back tomorrow, er, later today (it’s 12:01AM) and give you a hand (hopefully, applause, otherwise, coding help).

Regards,

DK

yippie, she fixed it as you suggested: using slugs as UNIQUE fields rather than IDs (in this case swapped both, ‘cat_id’ and ‘listing_id’ w. ‘permalink’ in the code, and before that defined permalinks through slugs). Look

http://kauaiwedpro.com/rebuild

no matter what you click, the correct path w. correct labels is now displayed in the URL, as supposed!

Above mod_rewrite string has remained, so I did it correct, thanks to your awesome guide!

So for your motivated collaboration I guess you may now pick a bride from the site (just no guarantee that shipping is included ^^ - and you might have to wrestle with a groom LOL)

Thanks again,
Lee

Lee,

Thanks for the enthusiastic reply! Thank you, I’ll take the one … yeah, right!

Unfortunately, I’ve never had the pleasure to visit Kauai although other visits have been to Oahu (Honolulu-based but toured the eastern half), Maui (Lahaina) and the Big Island (Kona Coast & drove around CCW). Maybe in my next lifetime.

Well, with the couple of members asking for details of my “Poor Man’s” RewriteMap, I’ll have to punch that up in my tutorial. Thanks for that nudge.

Regards (aloha),

DK

yes, a “Poor Man’s” RewriteMap rewrite would increase your popularity even more!

<OT>I always sensed you were speaking Hawaiian, too :wink: When you come to Kauai, don’t come during wintertime - it can be extremely wet (with thunderstorms getting harder each year), being the most northern of the populated islands. We had the strongest rains here since the '92 hurricane just recently, with the weather clearing up just now. So end of March seems to be start of Kauai visiting season these days. Anything before that starting w. January can turn into Russian roulette …</OT>

Lee,

My prior visits were August, July and (duh - summer). Lovely except for a day’s worth of rain around Hilo. After the Maui trip, I read about bike riding around the east side of Maui and had hoped to get back for that but … I guess I’ve got two trips planned for my next lifetime!

New Zealand’s been experiencing a very wet summer (1½" rain expected tonight) which is highly unusual (normally only the start of summer, i.e., December). Something’s going on weather-wise.

I’m in the middle of updating the tutorial page with a ton of information about RewriteMaps, none of which a webmaster can use, then describing how to extend that to a “Poor Man’s RewriteMap” using virtually the same PHP script as a “smart 404 handler.” I’m thinking I shouldn’t show much code for that - pseudo code should be sufficient for the non-script kiddies.

Regards,

DK