Filename extension optional?

Discuss practical ways rearrange URLs using mod_rewrite.

Filename extension optional?

Postby ohyoko2 » Wed Mar 02, 2005 3:20 pm

How would I change this rule so that it satisfies the following conditions: either, no filename extension is supplied, an .html filename extension is supplied, or a trailing slash is supplied.

Here's what I've so far:

Code: Select all
RewriteRule ^pages/([0-9A-Za-z_]+)/(.+)(.\html|/)$ /index.php?page=$1&section=$2 [L]
ohyoko2
 

Postby seomike » Wed Mar 02, 2005 8:33 pm

Code: Select all
#this will catch both the / and no /
RewriteCond %{REQUEST_URI} /([^/]+)/([^/]+)/?$
RewriteRule ^pages/.*$ /index.php?page=%1&section=%2 [L]

# this will do the .html
RewriteRule ^pages/([^/]+)/([^/]+)\.html$ /index.php?page=$1&section=$2 [L]


Give this a shot :)
seomike
 
Posts: 331
Joined: Thu May 06, 2004 7:36 pm
Location: Dallas

Postby ohyoko2 » Thu Mar 03, 2005 11:41 am

Yes, I know I could easily achieve that using two rules; but I want it all in one. Is there a way? (Caterham...?)
ohyoko2
 

Postby Caterham » Thu Mar 03, 2005 1:35 pm

Yes, I know I could easily achieve that using two rules; but I want it all in one
have a try on
Code: Select all
RewriteRule ^pages/([a-z0-9_-]+)/([a-z0-9_-]+)(\.html|/)?$ /index.php?page=$1&section=$2 [NC,L]


NC makes the pattern attern case-insensitive (ie. no differnce bezween a-z and A-Z)

Robert
Caterham
 
Posts: 690
Joined: Fri Dec 10, 2004 1:30 pm


Return to Friendly URLs with Mod_Rewrite

Who is online

Users browsing this forum: No registered users and 6 guests

cron