skip to Main Content

I have a problem with the Rewrite options and I can’t find the right answers on the internet so I hope this community can help me.

I am working local on a web project and use XAMPP as my local webserver.
I made a VirtulHost (basic.localhost) and now there is my problem with the mod_rewrite options.

When there is an url: basic.localhost/index.php/var1=option1&var2=option2&var3=option3&var4=option4
I want to rewrite the url to this: basic.localhost/option/option2/option3/option4

The var1 to var4 variables are used as GET variables to select content from an database.
This is my .htaccess now:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
</IfModule>

And all Rewrite Rules that I tried does not work…

2

Answers


  1. Chosen as BEST ANSWER

    I found an answer for the problem with the variables:

        <IfModule mod_rewrite.c>
            RewriteEngine On
            RewriteCond %{REQUEST_FILENAME} !-f
            RewriteCond %{REQUEST_FILENAME} !-d
            RewriteRule ^([^/]+)/([^/]+)/([^/]+)/([^/]+)$ index.php?var1=$1&var2=$2&var3=$3&var4=$4 [L,QSA]
            RewriteRule ^([^/]+)/([^/]+)/([^/]+)$ index.php?var1=$1&var2=$2&var3=$3 [L,QSA]
            RewriteRule ^([^/]+)/([^/]+)$ index.php?var1=$1&var2=$2 [L,QSA]
            RewriteRule ^([^/]+)$ index.php?var1=$1 [L,QSA]
        </IfModule>
    

    Now there is only the Problem with the index.php.


  2. I finally got a solution for this:

    <IfModule mod_rewrite.c>
        RewriteEngine On
        RewriteCond %{THE_REQUEST} ^GET.*index.php [NC]
        RewriteRule (.*?)index.php/*(.*) /$1$2 [R=301,NE,L]
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteRule ^([^/]+)/([^/]+)/([^/]+)/([^/]+)$ index.php?var1=$1&var2=$2&var3=$3&var4=$4 [L,QSA]
        RewriteRule ^([^/]+)/([^/]+)/([^/]+)$ index.php?var1=$1&var2=$2&var3=$3 [L,QSA]
        RewriteRule ^([^/]+)/([^/]+)$ index.php?var1=$1&var2=$2 [L,QSA]
        RewriteRule ^([^/]+)$ index.php?var1=$1 [L,QSA]
    </IfModule>
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search