Some help please -- Code Attempt Provided

Discuss practical ways rearrange URLs using mod_rewrite.

Some help please -- Code Attempt Provided

Postby worleyjbird » Thu Jun 19, 2008 4:00 pm

Hello!

When users click this URL -> http://www.domain.com/support/faq/7/

I need to rewrite that so the URL is -> http://www.domain.com/support/faq/

Bonus question, in the existing URL, since the '7' is a folder and there a bunch more, can I have it so that when someone hits any folder in http://www.domain.com/support/faq/<whatever folder>, that it always go to http://www.domain.com/support/faq/

Here is what I have:
RewriteRule ^/support\/faq\/7/ support/faq/ [L]

Aside from the syntax help, does the .htaccess file need to be in the web root directory *AND* in the 'support' folder as well? Or can I just have it in the web root directory?
worleyjbird
 
Posts: 8
Joined: Mon May 19, 2008 2:01 pm

Solution posted

Postby worleyjbird » Fri Jun 20, 2008 10:47 am

I poked around the forum and found... SPAM. But seriously folks, I found someone that had a similar situation so I was able to cater the solution to my needs.

Here is what I wound up with:

RewriteEngine on
RedirectMatch 301 ^/support/faq/2/ /support/faq/

Boy, even after I get lucky figuring something out, I still have some sort of mental block whenever I had to do any URL redirecting. For some reason its just not intuitive to me. Hopefully one day it will sink in because my job requires it from time to time.
worleyjbird
 
Posts: 8
Joined: Mon May 19, 2008 2:01 pm

P.S. - I forgot

Postby worleyjbird » Fri Jun 20, 2008 10:51 am

If I change it around a little:

RewriteEngine on
RedirectMatch 301 ^/support/faq/(.*)/ /support/faq/

The (.*) will make so any of these URLs:

http://www.domain.com/support/faq/1/
http://www.domain.com/support/faq/2/
http://www.domain.com/support/faq/3/
http://www.domain.com/support/faq/4/
http://www.domain.com/support/faq/5/

All direct back to http://www.domain.com/support/faq/

Cool! :D
worleyjbird
 
Posts: 8
Joined: Mon May 19, 2008 2:01 pm


Return to Friendly URLs with Mod_Rewrite

Who is online

Users browsing this forum: No registered users and 90 guests

cron