Using _ within mod-rewrite urls!

Using mod_rewrite to handle various content issues

Using _ within mod-rewrite urls!

Postby zompus » Thu Aug 10, 2006 7:30 am

Hey Guys,

I'm trying to setup something to rewrite my .PSD files:

RewriteRule ^([a-z]+)/(.*).psd$ /psd_dump/$2.psd [L]

e.g.
site.com/phrase/1230323.psd < site.com/psd_dump/1230323.psd

Heres my full .htaccess code:
Code: Select all
Options +FollowSymLinks

RewriteEngine on

RewriteRule ^([a-z\_]+)/thumb_(.*).png$ /previews/thumbs/thumb_$2.png [L]
RewriteRule ^([a-z\_]+)/preview_(.*).png$ /previews/$2.png [L]
[B]RewriteRule ^([a-z]+)/(.*).psd$ /psd_dump/$2.psd [L][/B]
RewriteRule ^search/(.*)/$ /make_search.php?search=$1 [L]
RewriteRule ^sitemap/$ /sitemap/sitemap.txt [L]
RewriteRule ^about/$ /about.php [L]
RewriteRule ^contact/$ /contact.php [L]
RewriteRule ^usercp/$ /usercp.php [L]
RewriteRule ^admin/$ /admin/index.php [L]
RewriteRule ^news/$ /news.php [L]
RewriteRule ^forums/$ /forums/index.php [L]
RewriteRule ^authors/$ /authors.php [L]
RewriteRule ^browse/(.*)/(.*)/index.html$ /browse.php?cat=$1&subcat=$2 [L]
RewriteRule ^browse/(.*)/index.html$ /browse.php?cat=$1 [L]
RewriteRule ^browse/index.html$ /browse.php [L]
RewriteRule ^browse/$ /browse.php [L]
RewriteRule ^(.*)/index.html$ /subpage.php?name=$1 [L]
RewriteRule ^(.*)/$ /subpage.php?name=$1 [L]
RewriteRule ^(.*)/(.*).html$ /subpage.php?name=$1&id=$2 [L]
Heres the problem, this kinda of url would work:

site.com/sample/1230823.psd, but this wouldnt: site.com/sample_sample/1230823.psd

Notice the "_" .. I'm not sure how i'd fix this within the rewrite, any ideas?
zompus
 
Posts: 2
Joined: Thu Aug 10, 2006 7:29 am

Postby richardk » Thu Aug 10, 2006 8:46 am

Try this:
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteRule ^(about|contact|usercp|news|authors|browse)/$ /$1.php [L]
RewriteRule ^(forums|admin)/$ /$1/index.php  [L]
RewriteRule ^sitemap/$ /sitemap/sitemap.txt  [L]
RewriteRule ^browse/index\.html$ /browse.php [L]
RewriteRule ^search/(.+)/$ /make_search.php?search=$1 [L]
RewriteRule ^[a-z_]+/thumb_([^/]+)\.png$   /previews/thumbs/thumb_$1.png [L]
RewriteRule ^[a-z_]+/preview_([^/]+)\.png$ /previews/$1.png [L]
RewriteCond %{REQUEST_URI} !^/psd_dump(/.*)?$
RewriteRule ^[a-z_]+/([^/]+)\.psd$ /psd_dump/$1.psd [L]
RewriteRule ^browse/([^/]+)/([^/]+)/index.html$ /browse.php?cat=$1&subcat=$2 [L]
RewriteRule ^browse/([^/]+)/index.html$         /browse.php?cat=$1           [L]
RewriteRule ^([^/]+)/(index.html)?$ /subpage.php?name=$1       [L]
RewriteRule ^([^/]+)/([^/]+).html$  /subpage.php?name=$1&id=$2 [L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby zompus » Thu Aug 10, 2006 9:30 am

Thanks, that seem'd to work :)
zompus
 
Posts: 2
Joined: Thu Aug 10, 2006 7:29 am


Return to Content

Who is online

Users browsing this forum: No registered users and 2 guests

cron