Problem with htaccess rewrite condition
I needed to redirect example.com/var1/var2/var3/... to
example.com/index.php?myvars=var1/var2/var3/...
This is the code I wrote myself:
RewriteEngine On
RewriteCond %REQUEST_URI !=/index.php
RewriteRule ^(.*)$ index.php?myvars=$1 [L,QSA]
I really want to understand why this does not work, and what solution would work. I need help from you guys, not just to make it work, but to help me understand. When I try my code, it keeps running forever and the page does not load. I don't know why, because I did not copy this code, I studied regex and htaccess to learn, but it did not work.
I've taken this form a similar project I had last year, and adopted it a bit. That worked fine for me.
RewriteEngine On
#Optional if you have issues with a subdirectory
#RewriteBase /path/on/your/server/
RewriteCond %REQUEST_FILENAME !-f
RewriteCond %REQUEST_FILENAME !-d
RewriteRule ^(.*)$ index.php?myvars=$1 [L]
The problem in your case is probably that = behind the ! The RewriteCondin my example simply make sure that they do not redirect if it's a valid file or directory. Probably even better than just ignoring the index.php as in your example. If you definately want to do so try: RewriteCond %REQUEST_URI !^/index.php that should do the trick as well (untested).
Comments
Post a Comment