how to hide folder name from url using .htaccess

后端 未结 3 1200
离开以前
离开以前 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:34

    You can try this

    RewriteEngine on
    RewriteCond %{REQUEST_URI} !^/(public)
    RewriteRule (.*) /public/$1
    
    0 讨论(0)
  • 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]
    
    0 讨论(0)
  • 2021-01-24 01:50

    try this

    RewriteEngine On    
    RewriteRule (.*) public/$ [QSA,L]  
    
    0 讨论(0)
提交回复
热议问题