Jump to content

Another Mod_Rewrite Question


Jumpy09

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/242356-another-mod_rewrite-question/
Share on other sites

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.

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.