
06-20-09, 02:30 PM
|
|
Aspiring Coder
|
|
Join Date: Mar 2009
Location: North Carolina, USA
Posts: 516
Thanks: 5
Thanked 47 Times in 44 Posts
|
|
From another forum,
Quote:
Hello all,
After a couple of late nights of intense focus on URI rewriting I am now ready to show you my 'code baby' up for some scrutiny. I am not after a ready made fix, but some helpful pointers to adapt the code if neccesary would be great. I can work from there, but keep in mind that until 3 days ago my knowledge was 0. Thanks to all for all previous useful posts&answers and tutorials at webmasterworld.
This is what I wanted:
rewrite
http://www.example.com/year1969
plus
http://www.example.com/summerof/year1969
to
http://www.example.com/index.php?page=year1969
and
http://www.example.com/index.php?page=summerof_year1969
resp.
And this is how I achieved this:
Options +FollowSymLinks
rewriteEngine on
rewriteCond %{REQUEST_URI}!(\.(gif¦jpg¦css)¦/index\.php)$
rewriteRule ^([^/]+)/?$ /index\.php?page=$1
rewriteRule ^([^/]+)/([^/]+)/?$ /index\.php?page=$1_$2 [L]
Although all my links to imgs and the css are relative to the server I did run into some problems with some of my images not being shown. Only when I moved the images to a deeper directory (from /images/ to /images/images2/ and changed the link correspondingly they were shown [strange].
Could someone shine a light on why only the deeper dir. structure for images would work? Also, any comments on the rewrite will be greatly appreciated.
Thanks
Skylla
Not sure where your non-working images were originally located, but here's a guess: Because a rewriteCond applies only to the first rewriteRule that follows it, your second rule is unconditional, and will rewrite images in any first-level subdirectory (i.e. /SubdirectoryName/ImageName.ImageType) to /index.php?page=SubdirectoryName_ImageName.ImageTyp e
There are several ways to fix this problem. Here are three of them.
Repeat the rewriteCond:
rewriteCond %{REQUEST_URI} !(\.(gif¦jpg¦css)$¦^/index\.php$)
rewriteRule ^([^/]+)/?$ /index\.php?page=$1
#
rewriteCond %{REQUEST_URI} !(\.(gif¦jpg¦css)$¦^/index\.php$)
rewriteRule ^([^/]+)/([^/]+)/?$ /index\.php?page=$1_$2 [L]
-or-
Stop mod_rewrite processing & exit if image or index.php requested:
rewriteRule \.(gif¦jpg¦css)$¦^index\.php$ - [L]
#
rewriteRule ^([^/]+)/?$ /index\.php?page=$1
rewriteRule ^([^/]+)/([^/]+)/?$ /index\.php?page=$1_$2 [L]
-or-
Skip only these two rules if image or index.php requested; Resume execution of any subsequent rules:
rewriteRule \.(gif¦jpg¦css)$¦^index\.php$ - [S=2]
#
rewriteRule ^([^/]+)/?$ /index\.php?page=$1
rewriteRule ^([^/]+)/([^/]+)/?$ /index\.php?page=$1_$2 [L]
Replace the broken pipe "¦" characters above with solid pipe characters before use; Posting on this forum modifies the pipe characters.
Jim
|
Hope this helps.
|