how to hide folder name from url using .htaccess

后端 未结 3 1199
离开以前
离开以前 2021-01-24 01:08

I have a domain example.com i want to redirect it to example.com/public but /public folder should hide from the url.

I am using the below code in .htaccess to redirect,

3条回答
  •  迷失自我
    2021-01-24 01:45

    This should be your complete .htaccess:

    Options +FollowSymLinks -MultiViews
    # Turn mod_rewrite on
    RewriteEngine On
    RewriteBase /
    
    RewriteCond %{REQUEST_FILENAME}.php -f
    RewriteCond %{REQUEST_URI} !/$
    RewriteRule (.*) $1\.php [L]
    
    RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+dirname/([^\s]+) [NC]// here you write your directory
    RewriteRule ^ %1 [R=301,L]
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule (?!^dirname/)^(.*)$ /dirname/$1 [L,NC]
    

提交回复
热议问题