Hide directory name from url

I just want to hide the dir name from the URL.

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

This code does not work for me, I probably made some mistakes

RewriteBase / RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule / /dir/$1 [L] 

I already have this .htaccess (to hide the php extension)

 RewriteEngine On RewriteCond %{REQUEST_FILENAME}.php -f RewriteCond %{REQUEST_URI} !/$ RewriteRule (.*) $1\.php [L] 
+6
source share
1 answer

This should be your full .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} ^[AZ]{3,}\s/+dirname/([^\s]+) [NC] RewriteRule ^ %1 [R=301,L] RewriteCond %{REQUEST_FILENAME} !-f RewriteRule (?!^dirname/)^(.*)$ /dirname/$1 [L,NC] 
+10
source

Source: https://habr.com/ru/post/952216/


All Articles