.htaccess http://example.com/site/login rewrite to http://example.com/login

hello again, yesterday i made a few changes to the logic of my website, first i decided that i will keep all the site wide view files in the protected/views/site/ folder, these include the homepage, the error404 page and the login page.

i am currently using .htaccess to rewrite the URL




Options +FollowSymLinks

IndexIgnore */*

RewriteEngine on


RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d




RewriteRule . index.php




basically it turns this:

http://site.com/index.php?r=site/login

into this:

http://site.com/site/login

(or better said the other way around)

the problem is only with the login page, for example the file is here "protected/views/site/login.php"

and the only way to access it is with the http://site.com/site/login

but the "site" bit looks a bit bad in my opinion, is there a way to modify the .htaccess to allow me to use it as is for all views with the exception of the "site" view, which should look like:

http://site.com/login

instead of:

http://site.com/site/login

i have tried rewriting some rules, adding some rules to the .htaccess file, but i dont seem to catch the login on how to do this, im even starting to wonder if its possible for all the names in the site directory.

i have tried this


RewriteRule ^login$ index.php

just for the sake of it, but it seems my .htaccess skills are a little rusty because i cant get anything to work…

Add ‘login’=>‘site/login’ to your rules array defined in config file (urlManager component).

oh! thanks again! i would never have figured this out.

it also finally snapped in me

the config/main.php file has a array of CComponent’s, with its individual tricks and additional array of rules to customize the default behavior of the framework!!!

i never noticed this explanation anywhere!

what rule do i need to add to enable the file extension .html to all of the files except the ones inside view/site/

??

so far i changed it in the actual CurlManager.php file


public $urlSuffix='.html';

hahah, no need i figured it out

i needed to add


'urlSuffix' => '.html',

to the config/main.php file

for those looking to solve same problem…

protected/config/main.php




		'urlManager'=>array(

			'urlFormat'=>'path',

			'showScriptName' => false,

			'urlSuffix' => '.html',

			'rules'=>array(

				'login'=>'site/login',

			),

		),



.htaccess in webroot


Options +FollowSymLinks

IndexIgnore */*

RewriteEngine on


RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d


RewriteRule . index.php