Forum Moderators: phranque
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
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]
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]
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]
Jim