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

.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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.