0

How to remove dynamic & static folder name from url using htaccess

example.com/theme/dynamicfolder/

to

example.com/

theme is static directory & dynamicfolder is value from mysql database

my current htaccess script

Options -MultiViews
RewriteEngine On   
RewriteBase /

RewriteCond %{HTTP_HOST} ^www\. [OR]
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$
RewriteRule ^ https://%1%{REQUEST_URI} [NE,L,R=301]

# external redirect to redirect old URL to pretty URL    
RewriteCond %{THE_REQUEST} /a\.php\?slug=([^\s&]+) [NC]
RewriteRule ^ /article/%1? [R=301,L,NE]


RewriteCond %{THE_REQUEST} /sitemap\.php [NC]
RewriteRule ^ /sitemap.xml [R=301,L,NE]

RewriteCond %{THE_REQUEST} /contact\.php [NC]
RewriteRule ^ /contact [R=301,L,NE]


# internal rewrite to forward to actual URL
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^article/([\w-]+)/?$ a.php?slug=$1 [L,QSA]


RewriteRule ^sitemap\.xml$ sitemap.php [L]
RewriteRule ^contact$ contact.php [L]
Prashant
  • 143
  • 1
  • 1
  • 7

1 Answers1

0

At the end of current .htaccess file in the root directory.

Add the following:

RewriteCond %{REQUEST_URI} !^staticFolder/
RewriteRule ^(.*)$ staticFolder/anotherFolder/$1 [L,QSA]

So the url:

https://yourdomain.tld/staticFolder/anotherFolder/any0therValue

Can be accessed from:

https://yourdomain.tld/any0therValue

But in that case, the anotherFolder should be predefined.

Hossam
  • 1,126
  • 8
  • 19