2

Here is my site url structure as follows: http://www.sitename.com/new/about-us .

What I really want to do now is hide the directory name 'new' from the above url, but the admin url should remain unchanged.

The admin url would be like : http://www.sitename.com/new/admin .

My previous .htaccess code as follows:

  RewriteEngine On
  RewriteBase /new/

  RewriteCond %{HTTP_HOST} !^www\.
  RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/new/$1 [R=301,L]

  RewriteRule blog/ - [L]
  RewriteRule (^wlp) - [L]

  RewriteRule admin/ - [L]

  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %(REQUEST_FILENAME} !-d
  RewriteRule ^([\S\s/+.]+)/?$ index.php?url=$1 [QSA,L]

Here is my server directory structure:

  /public
    /new
      .htaccess
      index.php
      about-us.php
      /blog
      /admin

Any help in this regard will be highly appreciated.

2 Answers 2

4

It sounds like what you are trying to accomplish is a common technique which I've seen before for forwarding all public_html requests to public_html/public to essentially hide the contents of the public_html directory from the user and making public_html/public the new web root.

Try using this in your public_html/.htaccess file (you can write further htaccess in public_html/new/.htaccess):

RewriteEngine on
RewriteBase /

#enforce www subdomain
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} ^sitename.com [NC]
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

#forward all requests, except new/admin, to the 'new' directory without the user's awareness
RewriteRule  new/admin  -  [S=2]
RewriteRule  ^$ new/    [L]
RewriteRule  (.*) new/$1 [L]
Sign up to request clarification or add additional context in comments.

4 Comments

I looked and that is the directory structure I was expecting however you are using public instead of public_html. So when I say public_html/.htaccess that means public/.htaccess. Meaning to put my .htaccess into your web root: /. Regarding your old htaccess file sitting in /new/.htaccess, it requires no edits.
Thanks for your co-operation. I have followed your response and put the newly created .htaccess file (with your above code) under public directory. My previous .htaccess file which is under 'new' directory retain unchanged. Currently the homepage works fine. But when I click on 'about-us' page it doesn't work. Here is my site url : spadvertising.com.
You may have to adjust the code in your index.php accordingly to match the $_GET['url'] being passed in. What happens if at the top of your index.php you do: echo $_GET['url'];exit; before anything else has a chance to run and you visit spadvertising.com/about-us? does it get rewritten to new/about-us properly or does it remain about-us?
I see your test and it isn't including the /new/ as I was expecting. I believe all you need to do now is edit your /new/.htaccess file's rewrite to add it in for the $_GET['url'] like so: RewriteRule ^([\S\s/+.]+)/?$ index.php?url=new/$1 [QSA,L]
0

This .htaccess in / should do:

RewriteEngine on
RewriteCond %{REQUEST_URI} !^new/
RewriteRule ^(.*)$ new/$1 [L]

1 Comment

there may be an another reason for that.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.