2

My URL was

http://demo.example.com/parentFolder/

but i have to redirect it to child folder, URL as

http://demo.example.com/parentFolder/ChildFolder/

i have redirect it in htaccess as

<IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{HTTP_HOST} ^(www.)?demo.example.com/parentFolder$ RewriteCond %{REQUEST_URI} !^/ChildFolder/ RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ /ChildFolder/$1 #RewriteCond %{HTTP_HOST} ^(www.)?demo.example.com/parentFolder$ RewriteRule ^(/)?$ ChildFolder/ [L] </IfModule> 

but didn't remove sub folder(ChildFolder) from URL. i want to access childFolder after redirect but want to hide childFolder from URL.

7
  • What url are you going to and what do you expect to happen? Commented Jan 23, 2018 at 6:20
  • @starkeen i want to acess childFolder and also want to hide childFolder from url Commented Jan 23, 2018 at 6:28
  • 1
    RewriteCond %{HTTP_HOST} ^(www.)?demo.example.com/parentFolder$ will never match as HTTP_HOST means your domain name not the path. Commented Jan 23, 2018 at 6:46
  • but it is redirecting Commented Jan 23, 2018 at 6:48
  • @starkeen do you have any suggestion ? Commented Jan 24, 2018 at 5:20

1 Answer 1

1
+50

You can use these rule in parentFolder/.htaccess:

RewriteEngine On # remove ChildFolder from URL show in browser RewriteCond %{THE_REQUEST} \s/+(parentFolder)/ChildFolder/(\S*)\s [NC] RewriteRule ^ /%1/%2 [R=301,NE,L] # add ChildFolder internally RewriteRule ^$ ChildFolder/ [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(?!ChildFolder/).*$ ChildFolder/$0 [L,NC] 
Sign up to request clarification or add additional context in comments.

6 Comments

I have applied it working perfectly but i face one more issue as i applied it for angular project, i have to change its base path also for index.html, when i change base path it doesn't get JS files etc what should i do for it except to write path statically. Thanks in advance :)
Unfortunately I don't know anything about AngularJS. May be, you need to add <base href="/base-path/" /> just below <head> section of your page's HTML to resolve js/css/images path.
if i add path then it shows children folder path in URL
i cannot share real URL here it's confidential. Although URL is like demo.example.com/ParentFolder/ChildrenFolder/ .
Thanks buddy now its working fine i just remove children folder name from base path.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.