简体   繁体   中英

htaccess hide subdirectory from url after redirect

I have same application running in local server - one in 'localhost', another in 'localhost/bss/'. My domains port forwarded to them. So www.domain.com:1111 and sub.domain2.info:1111 points to localhost. Now both of them showing localhost. I need to redirect sub.domain2.info:1111 (localhost) to sub.domain2.com:1111/bss/ (localhost/bss) but dont want to see '/bss'

My .htaccess in localhost is currently like this -

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.*)$ /index.php/$1 [L]

Options -Indexes 

RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)sub.domain2.info:1111$
RewriteRule (.*) /bss/$1 [R=301,L]

Nothing particular in .htaccess in localhost/bss -

RewriteEngine On
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.*)$ /index.php/$1 [L]

Options -Indexes

I would highly appreciate your response. Tried a few but nothing seems to work!

Assuming that you are using Apache Server for achieving this. If you are working on local environments you can try out with Virtual Hosts also Can you try this for your Subdomain

RewriteEngine on

RewriteCond %{HTTP_HOST} ^sub\.domain2\.com$
RewriteCond %{REQUEST_URI} !^/bss
RewriteRule ^(.*)$ /bss/$1 [L]

Adding this by seeing your comment you can set up virtualhosts in linux

By the way, I didn't understand why you using these ports in domain names

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM