lazytiger Posted September 26, 2005 Posted September 26, 2005 I'm experimenting with mod_rewrite on my site. I have a question about the extra directories it uses. In the following simple example, I am required to use an extra directory called "page" in the URL. RewriteEngine on RewriteRule ^page/([^/\.]+)/?$ index.php?page=$1 [L] So, for example, "http://lazytiger.com/page/whatever" would work, but "http://lazytiger.com/whatever" won't. Why must I have the extra "page" directory? Is there any way to have it not use an extraneous directory? I know simply taking "page" out of the rule doesn't work. Thanks. Quote
TweezerMan Posted September 26, 2005 Posted September 26, 2005 The 'page' directory (which isn't a real directory) is used by your mod_rewrite rule to construct a URL where whatever follows 'page' in the original URL is rewritten to be a 'page' URL parameter. Your rewrite rule takes the following URL: >http://lazytiger.com/page/whatever ...and rewrites it to the following: >http://lazytiger.com/index.php?page=whatever If you didn't want to use the 'page' directory in your URLs, you'd need to change the mod_rewrite rule so it's not looking for it in the original URL: >RewriteRule ^([^/\.]+)/?$ index.php?page=$1 [L] Depending on what other mod_rewrite rules you have in place, this change could break your site though. Quote
lazytiger Posted September 26, 2005 Author Posted September 26, 2005 Jeez, sometimes I'm annoyed at how easy things are! I removed the "page" but not the "/" after it from the rule. Regular expressions are so picky, and I don't know the ins and outs of them. I'm wondering why every example under the sun uses that extra directory if it's not necessary. Do people like deep directories? Thanks for helping me yet again, David! Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.