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

 

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

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.