1

How can I redirect every request to index.php? I also want the first 5 parameters as Get values.

Etc. /foo/bar/melon/car/berry/ would request index.php/?one=foo&two=bar&three=melon&four=car&five=berry (if only /foo/bar/ three, four and five would be empty etc.)

Is this possible and how?

1 Answer 1

1

You can use this code in your DOCUMENT_ROOT/.htaccess file:

RewriteEngine On
RewriteBase /

# skip all files and directories from rewrite rules below
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]

RewriteRule ^([^/]+)/?$ index.php?one=$1 [L,QSA]
RewriteRule ^([^/]+)/([^/]+)/?$ index.php?one=$1&two=$2 [L,QSA]
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/?$ index.php?one=$1&two=$2&three=$3 [L,QSA]
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/([^/]+)/?$ index.php?one=$1&two=$2&three=$3&four=$4 [L,QSA]
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/?$ index.php?one=$1&two=$2&three=$3&four=$4&five=$5 [L,QSA]
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you. Do you how I can make exceptions? Eg. /404/, should just request 404.php
You can add those specific rules just below RewriteBase line.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.