.htaccess hide subdirectory url after redirect

余生颓废 提交于 2019-12-01 08:42:23

Try with this: remove the redirect part then use this insead:

RewriteCond %{THE_REQUEST} ^GET\ /apt/
RewriteCond %{HTTP_HOST} ^(www\.)?mysite.com$
RewriteRule ^apt/(.*) /$1 [L,R=301]
RewriteCond %{HTTP_HOST} ^(www\.)?mysite.com$
RewriteRule !^apt/ apt%{REQUEST_URI} [L]

then use the same code for the main website.

If you want to remove /apt from url why do you redirect "/" to "/apt"? Try this:

RewriteRule !^apt/ /apt%{REQUEST_URI} [L,NC]

instead of

RewriteRule ^/?$ "http\:\/\/www\.mywebsite\.com/\apt" [R=301,L]

With this rewrite you should see your application in /apt folder under url www.mywebsite.com

Create a .htaccess file in root folder, and put this content inside (just change example.com and my_subdir):

 <IfModule mod_rewrite.c>
      RewriteEngine on
      RewriteCond %{HTTP_HOST} ^(www.)?example.com$
      RewriteCond %{REQUEST_URI} !^/my_subdir/
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteRule ^(.*)$ /my_subdir/$1
      RewriteCond %{HTTP_HOST} ^(www.)?example.com$
      RewriteRule ^(/)?$ my_subdir/index.php [L] 
    </IfModule>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!