Jump to content

how to redirect all urls of the main domain to a subfolder ?


sasori
Go to solution Solved by sasori,

Recommended Posts

here's the structure of the app

htdocs
   somefiles
    myfolder
       /image
       /js
       index.html
       style.css
   protected
      /models
      /controllers
      /blahblabha
  index.php
  .htaccess

what i want to happen is any stuff that I type after my domain name, should get redirected

to the /myfolder

 

like e.g

 

www.mydomain.com -> www.mydomain.com/myfolder (with or without www)

www.mydomain.com/blahblahbalh -> www.mydomain.com/myfolder  (with or without www)

dev.mydomain.com/omghowtodothis -> www.mydomain.com/myfolder (with or without www)

http://www.mydomain.com/help-me-please-/how-to-do-this -> www.mydomain.com/myfolder(with or without www)

 

so how to do that in .htaccess ?

 

 

at first i tried this

 

 

RewriteEngine On
RewriteCond %{HTTP_HOST} ^(http://www.)?mydomain.com$
RewriteCond %{REQUEST_URI} ^/(.*)+$ 
RewriteRule (.*) http://dev.mydomain.com/$1 [R=301,L]
RewriteRule ^$ /myfolder [L,R=301]

 

but it wasn't able to cater for the stuffs that i typed after the main domain URL such as in my example above

 

Edited by sasori
Link to comment
Share on other sites

This will redirect every directory request which not contains a file itself.

For instance /folder1, /folder2 but not /folder1.display.php

Try,

Options -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ /myfolder [QSA,L,R=307]

By the way, do you know any good online resource where I can watch "Naruto" with good quality?

Edited by jazzman1
Link to comment
Share on other sites

This will redirect every directory request which not contains a file itself.

For instance /folder1, /folder2 but not /folder1.display.php

Try,

Options -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ /myfolder [QSA,L,R=307]

By the way, do you know any good online resource where I can watch "Naruto" with good quality?

 

it says, page not redirecting properly...your suggested code , didn't worked at all,

any other ideas how to solve this thing ?

 

 

OFF TOPIC : here http://narutobase.net/Naruto-Shippuden-Episodes.html if you know the episode number , you can just browse youtube every weekend.

Link to comment
Share on other sites

 

......your suggested code , didn't worked at all

 

I really like that :)

 

So according your topic:

 

www.mydomain.com -> will be redirected to -> www.mydomain.com/myfolder

www.mydomain.com/blahblahbalh -> will be redirected to -> www.mydomain.com/myfolder

dev.mydomain.com/omghowtodothis ->will be redirected to -> www.mydomain.com/myfolder

 

So can you be more specific, please? Or....which part of the code doesn't work? 

Thank you for the link above :)

Link to comment
Share on other sites

  • Solution

nevermind , it got solved by just using

 

 

header("Location: to my chosen directory");
exit;

 

But i don't know why or how no matter what pattern I used in the .htaccess,

all the stuff that was typed after the slash of the main domain, shows "url not found in server",

maybe it's with the framework........moving on, atleast it got solved now without using .htaccess,

thanks for the time though...

 

Off Topic: by the way,I suggest you read the manga version of the naruto, it's more advance than the cartoon series :D www.mangastream.com

Link to comment
Share on other sites

He-he, I just forgot to add a dollar sign in my script here :)

 

Change:

RewriteRule ^ /myfolder [QSA,L,R=307]

to

RewriteRule ^$ /myfolder [QSA,L,R=307]

 

 

Off Topic: by the way,I suggest you read the manga version of the naruto, it's more advance than the cartoon series :D www.mangastream.com

 

I will :)

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.