-1

I have developed a simple mvc in php as my final project but the system uses ugly urls. I have looked around but it seems it is very advance: transform:

http://example.com/[subfolder]/controller/view/p:val/p:val/p:val
into:
http://example.com/[subfolder]/?m=controller&v=view&params[]=p:val&params[]=p:val&params[]=p:val

with unknown number of "p:val" and possibly subfolders. Can someone please help me?

I have read a tutorial where one can "connect" the .htaccess file to a php file to rewrite the url. I don't know how to connect the files.

1 Answer 1

0

Hmmmm you can map the whole request to your main php file using:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ /your_main_file.php [QSA,L]
</IfModule>

Now you can map the request:

preg_match('#/(?<controller>(\w+))/(?<view>(\w+)#', $_SERVER['REQUEST_URI'], $result);

And so on...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.