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 Link to comment https://forums.phpfreaks.com/topic/283515-htaccess-problem/ Share on other sites More sharing options...
requinix Posted November 1, 2013 Share Posted November 1, 2013 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). Link to comment https://forums.phpfreaks.com/topic/283515-htaccess-problem/#findComment-1456537 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.