0

I have a simple MVC application in PHP, all requests are handled by the following code in my htaccess file:

RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]

so if for example i have a url like app.com/profile/view/1

the url param will be "profile/view/1", this is segmented by the app and profile controller will be called, view action from the profile controller will be called, and the id 1 will be passed to the view method.

what i want to do is:

app.com/profile/1/seo-friendly-name-of-profile

but this doesn't work because its trying to find the action "1" in the profile controller.

What should i add to the htaccess file to achieve something like that?

tereško
  • 58,060
  • 25
  • 98
  • 150
  • This has little to do with "mvc" nor the RewriteRule. Since you are using a bland match-all (`.+` instead of separating id and path segments) and a routing scripting, you'll have to adapt your URL path dispatching script. – mario Feb 01 '15 at 20:28
  • are you suggesting that i should add a second rule here? or modify my php script that checks the segments and check if there is a profile keyword and do something else instead of trying to call the method? –  Feb 01 '15 at 20:35
  • @MichalisDaniilakis you might find this useful: http://stackoverflow.com/a/19309893/727208 – tereško Feb 03 '15 at 15:50

1 Answers1

-1

this is not .htaccess problem its more a PHP/URL parsing issue the easy way is to get

seo-friendly-name-of-profile

part parsed as parameter and handled in your controller This urlParsing code from simple MVC should get you started

Ahmed
  • 83
  • 2
  • 6