Mobile app version of vmapp.org
Login or Join
Pierce454

: 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

@Pierce454

Posted in: #Php #Redirects #UrlRewriting

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= [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.

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Pierce454

1 Comments

Sorted by latest first Latest Oldest Best

 

@Marchetta884

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= [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).

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme