skippt Posted November 1, 2013 Share Posted November 1, 2013 URLs look something like this: http://mysite.com/index.php?controller=1&method=2&arg=3 with the .htaccess added it looks like: http://mysite.com/1/2/3 Now if I want to go to a method within an index class I would have to do this: http://mysite.com/index/about My question is how would I be able to access the about page without putting /index/ before it? I've tried adding this to my .htaccess file: RewriteRule ^(.*)$ index.php which does work since I have to go to /app/view/css/style.css/ to access my stylesheets it breaks them.How would I do this without breaking my stylesheets?This is my .htaccess file: Options +Indexes +FollowSymLinks +Multiviews RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/(.*)$ index.php?url=$1&method=$2 [QSA,L] RewriteRule ^(.*)$ index.php Thanks Quote Link to comment https://forums.phpfreaks.com/topic/283515-htaccess-problem/ Share on other sites More sharing options...
Solution requinix Posted November 1, 2013 Solution Share Posted November 1, 2013 (edited) The example URLs you gave don't quite match up with your .htaccess. What actually happens is /1/2/3 -> index.php?url=1&method=2 /1/2/?arg=3 -> index.php?url=1&method=2&arg=3"Without putting /index/ before" is like saying "make the url optional with the default value of 'index'".You can basically duplicate the rule you have now but you have to make it accept only the one directory component (or else it'll conflict with what you have now), then pass url=index&method=$1. RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^([a-zA-Z0-9_-]+)/([^/]*)$ index.php?url=index&method=$1 [QSA,L]The [^/]* allows more after the directory and won't conflict with the other rule as long as you don't allow another trailing slash. Oh, and you probably want to do something with that trailing component (the $3 in the original rule and $2 in the new rule). Edited November 1, 2013 by requinix Quote Link to comment https://forums.phpfreaks.com/topic/283515-htaccess-problem/#findComment-1456537 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.