.htaccess not working for some reason

Associate
Joined
4 Mar 2007
Posts
315
Location
United Kingdom
Okay, it could be the fact that i'm not the best with dealing with .htaccess files
however my general site path is as follows:

index.php?page=index

where further modules can be assigned like so:

index.php?page=index/category/id

it even works for

index.php?page=index/category/sub-category/id

Now i've got the PHP which sorts this fine, works a charm, but I need to get rid of index.php?page=$1

I've tried

Code:
Options +FollowSymLinks

RewriteEngine On
RewriteRule ^(.*)$ index.php?page=$1

But to no avail it doesn't seem to be working at all. Any ideas ?

I really need it to display

http://www.site.com/index/category/id
instead of the long windedness

Regards
 
Add the [R] flag to the end of the rule so you can see where rules are sending you, might help you find a solution!

I think (my mod_rewrite skills leave a little to be desired..) that your problem is that your rewrite will get stuck in a loop;

user visits site.x/index/category/id
/index/category/id matches ^(.*)$
redirect to index.php?page=/index/category/id
but thenn...
index.php?page=/index/category/id matches ^(.*)$
redirect to index.php?page=index.php?page=/index/category/id
... and so on, or something dumb like that

ANYWAY
try
Code:
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule (.*) index.php?page=$1 [L]
This is similar, but won't execute the rule if the page being requested is an actual file or directory. This stops loops and will let you do things like request a CSS file correctly; if you tried to do that before the rule would catch it and run it through index.php!
 
Last edited:
Add the [R] flag to the end of the rule so you can see where rules are sending you, might help you find a solution!

I think (my mod_rewrite skills leave a little to be desired..) that your problem is that your rewrite will get stuck in a loop;

user visits site.x/index/category/id
/index/category/id matches ^(.*)$
redirect to index.php?page=/index/category/id
but thenn...
index.php?page=/index/category/id matches ^(.*)$
redirect to index.php?page=index.php?page=/index/category/id
... and so on, or something dumb like that

ANYWAY
try
Code:
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule (.*) index.php?page=$1 [L]
This is similar, but won't execute the rule if the page being requested is an actual file or directory. This stops loops and will let you do things like request a CSS file correctly; if you tried to do that before the rule would catch it and run it through index.php!

Brilliant, it didn't work all the time for some reason, but after a bit more research I tried this and it seemed to have done the job.

Code:
RewriteRule ^(.*)$ index.php?url=$1 [PT,L]
 
Back
Top Bottom