Web Hosting Talk







View Full Version : Subdirectory redirection


Jackis
03-09-2010, 09:12 AM
Hello

I need directory redirection like subdomain redirection.
cPanel has a function to redirect all subdomains to main folder if you enter "*" in subdomains settings. I need the same function just with directory.
For example:

I enter --> myurl.com/ANYTHING_HERE/myindex.html
opens --> myurl.com/myfolder/myindex.html but link is still the same as you entered.

Is it possible? Thanks for help

Palmetto Innovations
03-18-2010, 11:29 PM
You could do something similar with a rewrite in .htaccess. You would just have to use a regular expression in the middle there to catch "anything". Let me know if you need examples and I'll be happy to help!

eeadmin
03-19-2010, 01:04 PM
I agree with palmetto the easiest way is a .htaccess. If you have a frame work you work in with some sort of router then you can probably use that as well. But the .htaccess is more accessible.

Jackis
04-09-2010, 08:00 PM
You could do something similar with a rewrite in .htaccess. You would just have to use a regular expression in the middle there to catch "anything". Let me know if you need examples and I'll be happy to help!

I need examples! Can you or anyone help?

Palmetto Innovations
04-10-2010, 06:32 AM
Sorry for the delayed reply. For some reason, I didn't get an email saying there was a reply to the post. My understanding of what you want is this: rewrite anyDirectory/myindex.html to myfolder/myindex.html. There are other factors that play into this like: if you want the url to stay the same in the address bar and have stuff done behind the scenes, or have the user redirected to the page, whether you want a static myindex.html file presented or if you want to catch anydirectory/anyfile.html and redirect it to myfolder/anyfileofthesamename.html. If either of those are the case, let me know and I can do examples for those as well. As for the example below, it is to redirect anyDirectory/myindex.html to myfolder/myindex.html

OK, here's an example of what your .htaccess file should look like (remember this is assuming it's in your root directory):


RewriteEngine on
RewriteRule ^([0-9a-zA-Z]+)/myindex\.html$ myfolder/myindex.html


There are other ways to do this, but that is just a simple example that should get done what you want. Let me know if I can help any further!