Hide directory name from URL

前端 未结 1 1866
青春惊慌失措
青春惊慌失措 2020-12-10 07:06

I just want to hide the dir name from URL.

From: example.com/dirname/somepage To: example.com/somepage

相关标签:
1条回答
  • 2020-12-10 07:46

    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]
    RewriteRule ^ %1 [R=301,L]
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule (?!^dirname/)^(.*)$ /dirname/$1 [L,NC]
    
    0 讨论(0)
提交回复
热议问题