Fog Juice Posted July 7, 2011 Share Posted July 7, 2011 Hello, I have the following htaccess RedirectMatch 301 ^/.*$ http://mydomain.com/index.php What I would like to do is add it so the requested director would be added onto the http://mydomain.com/index.php. So for example, if someone were trying to access http://mydomain.com/folder then the .htaccess would redirect to http://mydomain.com/index.php/folder. I've been searching for hours on google but can't figure it out, does anyone have any tips? The .htaccess syntax is what confuses me. Thanks. *edit* I think I got it: RedirectMatch 301 (.*) http://mydomain.com/index.php$1 Quote Link to comment https://forums.phpfreaks.com/topic/241286-redirecting-director-to-filedirectory/ Share on other sites More sharing options...
gizmola Posted July 7, 2011 Share Posted July 7, 2011 What you probably want to look into is RewriteCond. These are conditions that when met, can be used to drive a rewrite rule. There are a variety of different variables pulled from the server environment that you can use. For example, if these directories exist, then this should handle it: RewriteCond %{REQUEST_FILENAME} -d RewriteRule ^(.*)$ /index.php/$1 Quote Link to comment https://forums.phpfreaks.com/topic/241286-redirecting-director-to-filedirectory/#findComment-1239402 Share on other sites More sharing options...
Fog Juice Posted July 7, 2011 Author Share Posted July 7, 2011 Hmm it seems that either one doesn't work when trying to go directly to the url, it results in http://yourdomain.com/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php Basically, there won't by any directories. All I need is a .htaccess that changes any http://yourdomain.com/nameofwhatever to http://yourdomain.com/index.php/nameofwhatever. Quote Link to comment https://forums.phpfreaks.com/topic/241286-redirecting-director-to-filedirectory/#findComment-1239424 Share on other sites More sharing options...
cags Posted July 7, 2011 Share Posted July 7, 2011 The RewriteCond you have redirects any request that isn't for a directory. You therefore request example.com/foo, which successfully re-directs to example.com/index.php/foo, which of course is itself not a directory, thus it will get re-directed. Therefore you need to either also stop it re-writing the index page, or more likely (assuming you will have other files on your sever, like images, css etc.), you need to not redirect requests for actual files. RewriteCond %{REQUEST_FILENAME} -f RewriteCond %{REQUEST_FILENAME} -d RewriteRule ^(.*)$ /index.php/$1 Quote Link to comment https://forums.phpfreaks.com/topic/241286-redirecting-director-to-filedirectory/#findComment-1239778 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.