php devp
php devp

Reputation: 75

Url rewriting for hiding folder name and open it without folder name

I hv used all my uls in action with root directory now i cant change all of them so i need to rewrite my home url which hides folder name and if someone opens that domain then data saved in that folder must also be opened but folder name should not be displayed in url i.e. i have this

http://example.com/foldername

.I want to change this in as

http://example.com

but it should automatically take foldername data .How this can be achieved by using ".htaccess" file

RewriteEngine On
# The following rule tells Apache that if the requested filename
# exists, simply serve it.
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
# The following rewrites all other queries to index.php. The 
# condition ensures that if you are using Apache aliases to do
# mass virtual hosting, the base path will be prepended to 
# allow proper resolution of the index.php file; it will work
# in non-aliased environments as well, providing a safe, one-size 
# fits all solution.
RewriteCond %{REQUEST_URI}::$1 ^(/.+)(.+)::\2$
RewriteRule ^(.*) - [E=BASE:%1]
RewriteRule ^(.*)$ %{ENV:BASE}index.php [NC,L]

This is the .htaccess file i am currently using

Upvotes: 0

Views: 3794

Answers (2)

Mohammed Elhag
Mohammed Elhag

Reputation: 4302

Change your .htaccess file like this

RewriteEngine On
RewriteCond %{THE_REQUEST} ^GET\ /foldername/
RewriteCond %{HTTP_HOST} ^(www\.)?yoursite.com$
RewriteRule ^foldername/(.*) /$1 [L,R=301]
RewriteCond %{HTTP_HOST} ^(www\.)?yoursite.com$
RewriteRule !^foldername/ foldername%{REQUEST_URI} [L]

Upvotes: 1

anubhava
anubhava

Reputation: 785206

Keep this rule in root .htaccess:

RewriteEngine On

RewriteRule ^(?!foldername/)(.*)$ foldername/$1 [L,NC]

Then have this simplified code in /fodlername/.htaccess:

DirectoryIndex index.php
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]

Upvotes: 2

Related Questions