954,242 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

.htaccess Directory Redirects

You will have to excuse if this question seems stupid but while I am a fairly skilled PHP developer I am a total newb when is comes to apache and server config.

I am trying to have a single page accept all the request for directories on my site unless the requested directory actually exists. The most common example I see of this is in wordpress though I cannot figure out how wordpress is actually acomplishing it. This is probably best communicated through example

say some one requests

http://mydomain.com


simple, apache gives them my index.php file. Now lets say someone requests

http://mydomain.com/post/some-random-post


yet there is no directory on my server called /post/ .What I would like is for that request to be redirected back to

http://mydomain.com/index.php?request=post/some-random-post


yet I still want the user to see their original request in the URL bar of

http://mydomain.com/post/some-random-post


my index.php page will then parse that variable 'request' and deliver the apropriate content to the visitor.

now there is one other consideration and that is for directories that do exist such as the /images directory. I need to be able to still serve my images dir requests or any other dir that exists. So if some one requests

http://mydomain.com/images/logo.jpg


The image that exists at that location would be delivered.

From what I have found this should require just the .htaccess file to handle all server requests. This is what I have thus far.

RewriteEngine on
RewriteRule ^(.*)$ http://mydoamin.com/index.php?request=$1


This however results in a continuous loop of the server looking for index.php

Any helpful direction on this would be very appreciated. I have looked through a number of mod Rewrite explanations but cannot get this figured out

ajbest
Light Poster
31 posts since Apr 2010
Reputation Points: 12
Solved Threads: 4
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: