Problem with htaccess rewrite condition

Problem with htaccess rewrite condition - If a page has internal and external outgoing links to redirecting URLs, it’s returning 3xx (301, 302, etc.) HTTP status codes standing for redirection. This issue means that the page does not exist on a permanent or temporary basis. It appears on most of the popular web browsers, usually caused by a misconfigured website. However, there are some steps you can take to ensure the issue isn’t on your side. You can find more details about redirecting URLs by reading the Google Search Central overview. In this article, we’ll go over how you can fix the Problem with htaccess rewrite condition error on your web browser. Problem :


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.


Solution :

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


We hope that this article has helped you resolve the php, redirects, url-rewriting error in your web browsers. Enjoy browsing the internet uninterrupted!

Comments

Popular posts from this blog

How to redirect to any domain [duplicate]

"302 found" for index page bad for SEO?

Create redirect from url like www.example.us/?p=100&option=