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
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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.