Ijas Ahamed Ijas Ahamed - 11 days ago 6
Apache Configuration Question

.htaccess - Remove a word from url

I have a project directory structure as below

| project
--| controllers
--| views
--| index.php
--| .htaccess
--| config
--| .htaccess


Here's my main .htaccess

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)?$ views [L]
</IfModule>


and my view .htaccess

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^.+$ index.php [L]
</IfModule>


I am able to redirect all my requests to views/index.php. When i go to www.example.com/project it will be redirected to www.example.com/project/views.

My main problem is i don't want to have views in my URL. If i go to www.example.com/project it should execute views/index.php but URL does not change. Can anyone help me to figure out this problem?

Answer

Keep this in main .htaccess:

RewriteEngine On
RewriteRule .* views/$0 [L]

Then have it like this in .views/.htaccess:

RewriteEngine on

RewriteRule ^index\.php$ - [L,NC]

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