Here’s a complex problem I am facing right now on my project is that I want to remove the folder name from the URL from
http://www.example.com/pages/contact-us.html
to
http://www.example.com/contact-us.html
Hence removing the /pages/ in this case –
This is my file structure- File Structure
Now to access the files we have to access the pages then contact-us first so to remove this I have used this .htaccess code below –
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteCond %{REQUEST_URI} !/$
RewriteRule (.*) $1.php [L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}s/+pages/([^s]+) [NC]
RewriteRule ^ %1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (?!^pages/)^(.*)$ /pages/$1 [L,NC]
When I use this the URLs can be accessed without using /pages/ but the homepage doesn’t appear
You could implement some kind of permanent redirect:
<?php header("HTTP/1.1 301 Moved Permanently"); header("Location:
http://www.example.com/contact-us.html); exit ?>
Like this you can simply redirect the old url to the new one
Please login or Register to submit your answer