Welcome Guest, Not a member yet? Register   Sign In
removing .php extension with htaccess?
#1

[eluser]chobo[/eluser]
Does anyone how to remove the .php extension from a url? I'm using dreamweaver and if I click on a controller (ex blog.php) and view it by pressing F12, it opens it in the browser with the path http://mysite/blog.php which is invalid because the controller is just "blog" without the extension.

It kind of sucks to manually remove the .php every time you want to run a file. Any help is appreciated.
#2

[eluser]chobo[/eluser]
I've got a partial solution but it needs a lot of work. I kind of suck with mod-rewrite, so if anyone can help clean this up, I would appreciate it.


Code:
RewriteEngine on

#remove public_html part of path (dreamweaver adds this since it is not the root folder)
rewriteRule ^public_html/?(.*) /$1 [R=301,L]

#if the path is the controller path remove the .php extension
RewriteCond %{REQUEST_URI} ^CodeIgniter_1.5.4/system/application/controllers/?(.*)$
RewriteRule ^(.+)\.php$ /$1 [R=301,L]

#remove the controller path (not sure how far that condition above applies too)
rewriteRule ^CodeIgniter_1.5.4/system/application/controllers/?(.*) /$1 [R=301,L]

#I'm not sure what the bottom does I think it ignores those few things
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 [L,QSA]

I also set my:
$config['index_page'] = "";
#3

[eluser]bradym[/eluser]
Take a look at this wiki entry: http://codeigniter.com/wiki/mod_rewrite/.
#4

[eluser]chobo[/eluser]
Given the following url:

Code:
http://sitename.local/CodeIgniter_1.5.4/system/application/controllers/welcome.php


How can I change that to

Code:
http://sitename.local/welcome


I have taken care of the index.php thing with the following code.
Code:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]

I know for a fact taht the above can be done,, I just suck real bad at mod-rewrite, but I'm confident someone here knows how to use it. The code to get rid of most of that path needs to work in conjunction with the second code area that deals with the index.php.
#5

[eluser]Phil Sturgeon[/eluser]
If you have read the user guide you will know that you dont need to do this. You simply call the root folder (the folder containing system/) and it will load it for you.

Quote:http://sitename.local/welcome

will call the file

Quote:http://sitename.local/CodeIgniter_1.5.4/...elcome.php

but you dont access it directly or you lose the ENTIRE benefit of having the framework there. Dreamweaer doesnt understand this and so will treat it like normal PHP (meaning loads the page with the extention).
#6

[eluser]chobo[/eluser]
I'm not sure you guys are understanding the dilemma, even thought it is minor, it still sucks. When I load controller files from dreamweaver directly it throughs the whole path in there (hence the Codeingiter-1.5.4...). If I remove that bit using an .htaccess it screws up the part where it removes the index.php (code from taht wiki to handle getting rid of "index.php").

Maybe it's the order I'm doing things in the .htaccess file, or I'm not setting up the conditions right. Either way I'm just going to leave i, since it's more trouble then it's worth. I'd rather get the hang of using codeigniter first.
#7

[eluser]richard_ctv[/eluser]
[quote author="chobo" date="1185061310"]I'm not sure you guys are understanding the dilemma, even thought it is minor, it still sucks. When I load controller files from dreamweaver directly it throughs the whole path in there (hence the Codeingiter-1.5.4...).[/quote]

I use dreamweaver and for a long time I have been using frameworks and not using the f12 preview function.

Ive got use to having the site open in localhost, and just entering the url.

The number of keystrokes is one more - alt(or command) tab + refresh(command/ctrl + r) vs just f12.

Sorry, can't think of anything more elegant.

Also, there is a feature is CI that allows you to add an extension to you files - perhaps enabling this would help?
#8

[eluser]chobo[/eluser]
Ya, I was going for the ultimate in shortcuts, but this is more of a dreamweaver issue, so i'll just leave it for now.
#9

[eluser]n_uryanto[/eluser]
great information, thanks for share Smile

nuryanto




Theme © iAndrew 2016 - Forum software by © MyBB