Jump to content

.htaccess problem


Go to solution Solved by requinix,

Recommended Posts

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

  • Solution

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 by requinix
Link to comment
https://forums.phpfreaks.com/topic/283515-htaccess-problem/#findComment-1456537
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.