views:

19

answers:

2

Thanks to the people that've helped me so far with this, I'm ready for the last step, I think.

I've got my URLs looking like this.

/brochure.php?cat_path=35&name=concrete-intermediate-posts

This is great and finally I just need to know how to turn that URL into this desired URL:

/brochure/35/concrete-intermediate-posts

Just like the Stack Overflow format.

Could anyone help me with the correct .htaccess rule?

Also, if I have other get variables in other sections, will this re-write harm them? (they use different variable names)

Thanks

A: 

With mod_rewrite you will rather do the opposite: rewrite a URL path like /brochure/35/concrete-intermediate-posts internally to /brochure.php?cat_path=35&name=concrete-intermediate-posts:

RewriteRule ^([^/]+)/(\d+)/([^/]+)$ $1.php?cat_path=$2&name=$3 [L,QSA]

The other side, using a URL path like /brochure/35/concrete-intermediate-posts instead of /brochure.php?cat_path=35&name=concrete-intermediate-posts in the HTML documents, would be done with PHP.

Gumbo
That's thrown me a little, what result would this produce? my desired one?
shane
Gumbo
Ok that's great, thanks. So I first need to create my desired URL, and then use your code to allow it to make the correct requests?
shane
How would I go about changing the URL with PHP?
shane
@shane: Yep. I don’t know how you generate these URLs. But you just need to change the format so that the output looks like `/brochure/35/concrete-intermediate-posts`.
Gumbo
shane
shane
Sorry, It's all clicked now. Thanks alot for your help, as always.
shane
Scratch that. It's just returning 'page not found' as if the rewrite rule isn't kicking in/ Any common reasons for this? (host?)
shane
@shane: Do you use the obligatory `RewriteEngine on`?
Gumbo
Am I using the correct method to get this working. I've replaced my links with <a href="/brochure/29/concrete-posts">link<a/>.
shane
A: 

I Hope you mean something like this:

RewriteEngine On
RewriteBase /
RewriteRule ^brochure/([0-9]+)/([-a-zA-Z0-9]+)$ /brochure.php?cat_path=$1&name=$2 [L]
revaxarts