954,587 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Help with php and urls and maybe .htaccess

hi,

I am beginning my journing on php development and i am trying to do my own MVC framework. I have a huge problem whith URLS.

My URL Format:
http://example.com/index.php/Controller/Function/Arg1/Arg2/ArgN

everything is working fine but per example when i call it like:
http://example.com/index.php , The default Controller is called, no problems with that, but if i call like:

http://example.com/Controller/Function/Arg1/Arg2/ArgN ,

The default Controller is called again, and my script will only load the right controller if index.php is added in the URL like that:
http://example.com/index.php/Controller/Function/Arg1/Arg2/ArgN

there is a way to always include the index.php in the URLS request, maybe using .htaccess or some function, i tried to do many things but no success

bas_brain
Newbie Poster
8 posts since Apr 2009
Reputation Points: 10
Solved Threads: 0
 

.htaccess files use regular expressions to redirect so a URL like
http://mysite.com/somefile/user/hello.html
could be redirected to
http://mysite.com/index.php?file=somefile&arg2=user&arg3=hello
using the .htaccess file

#Enable URL Rewriting
RewriteEngine on

RewriteRule ^/([0-9a-zA-Z_-]+)/([0-9a-zA-Z_-]+)/([0-9a-zA-Z_-]+).html$ //index.php?file=$1&arg2=$2&arg3=$3 [QSA]

so in your example you just need somethingl ike

#Enable URL Rewriting
RewriteEngine on

RewriteRule ^/([0-9a-zA-Z_/-]+)$ //index.php/$1 [QSA]

I haven't tested that code but it should be OK

samarudge
Posting Whiz
359 posts since May 2008
Reputation Points: 26
Solved Threads: 31
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You