Mod Rewrite help

New to mod_rewrite? This is a good place to start.

Mod Rewrite help

Postby wwfc_barmy_army » Sun Nov 01, 2009 4:00 pm

Hello.

I currently has this htaccess:
Code: Select all
Options +FollowSymLinks
RewriteEngine on

RewriteRule ^index\.php / [R=301,L]
RewriteRule ^category_([^/\.]+)/?$ /index.php?cat=$1 [L]
RewriteRule ^section_([^/\.]+)/?$ /index.php?sect=$1 [L]


Works perfect when I go to mydomain.com/section_1 etc. But what I'm looking to do now is:

mydomain.com/section_1_meaningfultext.

Can you offer any advice?

Thanks.
wwfc_barmy_army
 
Posts: 7
Joined: Fri Aug 14, 2009 5:32 am

Postby richardk » Mon Nov 02, 2009 10:35 am

Try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

# Redirect to remove /index.php files.
RewriteCond %{THE_REQUEST} \ /(.+/)?index\.php(\?.*)?\  [NC]
RewriteRule ^(.+/)?index\.php$ /%1 [NC,R=301,L]

RewriteRule ^category_([0-9]+)_[^/]+/?$ /index.php?cat=$1 [L]
RewriteRule ^section_([0-9]+)_[^/]+/?$ /index.php?sect=$1 [L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby wwfc_barmy_army » Mon Nov 02, 2009 3:12 pm

Spot on mate. I'm learning slowly :)

Is there some reference I can use for the ([0-9]+) bits etc?

Thanks.
wwfc_barmy_army
 
Posts: 7
Joined: Fri Aug 14, 2009 5:32 am


Return to Beginner's Corner

Who is online

Users browsing this forum: No registered users and 7 guests

cron