Jumpy09 Posted July 19, 2011 Share Posted July 19, 2011 Alright I have gone through the forum and was looking for something that would fit my bill. The page in question has index.php, admin.php, and another .php file. The pages are called up index.php?page=pagelink which are used to render out the pages. I want to turn http://www.site.com/page into http://www.site.com/index.php?page=page but I don't want admin.php or the other .php file changed. So I am thinking about something like RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^([a-z])\.php $ ./$1\.php [QSA , OR] RewriteRule ^([a-z])? $ ./index.php?page=$1 [OR] RewriteRule ^([a-z])/? $ ./index.php?page=$1 [OR] RewriteRule ^(.*)\.css $ ./path/to/css/$1\.css [OR] RewriteRule ^(.*)\.js $ ./path/to/js/$1\.js[OR] RewriteRule ^(.*)\.png $ ./path/to/image/$1\.png[OR] RewriteRule ^(.*)\.jpeg $ ./path/to/image/$1\.jpeg[OR] RewriteRule ^(.*)\.jpg $ ./path/to/image/$1\.jpg[OR] RewriteRule ^(.*)\.gif $ ./path/to/css/$1\.gif[L] Does anything look wrong with this? Quote Link to comment https://forums.phpfreaks.com/topic/242356-another-mod_rewrite-question/ Share on other sites More sharing options...
requinix Posted July 19, 2011 Share Posted July 19, 2011 A few things, actually. Try RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^\w+$ index.php?page=$0 [L] Do you really need those image/et al. rules? Why? Quote Link to comment https://forums.phpfreaks.com/topic/242356-another-mod_rewrite-question/#findComment-1244774 Share on other sites More sharing options...
Jumpy09 Posted July 20, 2011 Author Share Posted July 20, 2011 A few things, actually. Try RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^\w+$ index.php?page=$0 [L] Do you really need those image/et al. rules? Why? Thank you, and no I don't need those. Just thought it would be pretty cool to use for image , js , and css calls. Just to play around with the rewrite. Could you explain why you changed the (A-Z) to the \w+ thing? I'm still trying to become proficient, so an explanation would help me understand what it was for and why what I did was bad. It may help me prevent from trying to do the same thing again. Quote Link to comment https://forums.phpfreaks.com/topic/242356-another-mod_rewrite-question/#findComment-1244952 Share on other sites More sharing options...
cags Posted July 20, 2011 Share Posted July 20, 2011 I believe that \w will match A-Za-z0-9_ and the + means 'one or more of'. Your patterns with [a-z] will only match a single lowercase letter. Quote Link to comment https://forums.phpfreaks.com/topic/242356-another-mod_rewrite-question/#findComment-1245018 Share on other sites More sharing options...
Jumpy09 Posted July 20, 2011 Author Share Posted July 20, 2011 Alright thanks for the explanation, I suppose I could use that but the only portion that would go there from me would be lowercase letters. Anything else would be inserted by other people, which is why I was aiming for the lowercase only. That should solve my problem. Quote Link to comment https://forums.phpfreaks.com/topic/242356-another-mod_rewrite-question/#findComment-1245325 Share on other sites More sharing options...
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.