Prajna Hegde
Prajna Hegde

Reputation: 740

How can hide directory name from the url using htaccess?

For example I have url like http://localhost/Experiments/login/login.php

I have hide the extention of file putting below code in .htaccess file

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
RewriteCond %{REQUEST_FILENAME}\.png -f
RewriteRule ^(.*)$ $1.png
RewriteCond %{REQUEST_FILENAME}\.css -f
RewriteRule ^(.*)$ $1.css
RewriteCond %{REQUEST_FILENAME}\.js -f
RewriteRule ^(.*)$ $1.js
RewriteCond %{REQUEST_FILENAME}\.jpg -f
RewriteRule ^(.*)$ $1.jpg
RewriteCond %{REQUEST_FILENAME}\.ico -f
RewriteRule ^(.*)$ $1.ico

how can I make the above url to http://localhost/login Even I tried for the solutions related to the same issue in stackoverflow but could not make it

Upvotes: 1

Views: 146

Answers (1)

anubhava
anubhava

Reputation: 786091

Insert this rule just below RewriteEngine On line:

RewriteEngine On

RewriteCond %{DOCUMENT_ROOT}/Experiments/login/$1.php -f
RewriteRule ^([\w-]+)/?$ Experiments/login/$1.php [L]

# remaining rules go below this

Upvotes: 1

Related Questions