Jump to content

redirecting director to file/directory


Fog Juice

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/241286-redirecting-director-to-filedirectory/
Share on other sites

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

 

 

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.

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

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.