/(.*)/(.*).html problem

Discuss practical ways rearrange URLs using mod_rewrite.

/(.*)/(.*).html problem

Postby overflow » Tue Jun 10, 2008 3:32 am

Code: Select all
RewriteCond  %{REQUEST_FILENAME} !^.*/(themes|logs|cgi-bin)($|/.*)
RewriteCond  !%{THE_REQUEST} /(.*)/(.*).html
RewriteRule  ^/([A-Za-z0-9-]+)($|/$) /SOURCEDIRECTORY/index.php?directory=$1 [L]

...
other rewrite rules


http://www.adres.com/PARAM1/PARAM2.html OR
http://www.adres.com/PARAM1($|/$)

if true SOURCEDIRECTORY/index.php?directory=PARAM1
else header 404

How Can I Do Rewrite
overflow
 
Posts: 19
Joined: Thu Oct 12, 2006 2:02 am
Location: Turkey

Postby richardk » Wed Jun 11, 2008 3:05 pm

You need to match it "or"
Code: Select all
Options +FollowSymLinks

RewriteEngine On

# Ignore these directories.
RewriteCond %{REQUEST_URI} !^/(themes|logs|cgi-bin)(/.*)?$ [NC]
# If it matches /<param1>/<param2>.html OR
RewriteCond %{REQUEST_URI} ^/([-a-z0-9]+)/([^/]+)\.html$ [NC,OR]
# it matches /<param1>/
RewriteCond %{REQUEST_URI} ^/([-a-z0-9]+)/?$ [NC]
# rewrite to /SD/index.php?directory=<param1>
RewriteRule . /SD/index.php?directory=%1 [QSA,L]


A shorter version using a regular expression instead of RewriteConds
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{REQUEST_URI} !^/(themes|logs|cgi-bin)(/.*)?$ [NC]
RewriteRule ^([-a-z0-9]+)(/([^/]+\.html)?)?$ /SD/index.php?directory=$1 [QSA,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby overflow » Thu Jun 12, 2008 12:03 am

Very thanks richardk
overflow
 
Posts: 19
Joined: Thu Oct 12, 2006 2:02 am
Location: Turkey


Return to Friendly URLs with Mod_Rewrite

Who is online

Users browsing this forum: No registered users and 70 guests

cron