JACK
JACK

Reputation: 103

How to redirect sub-directory to root directory with parameter as sub-directory using .htaccess

Want to Redirect to index.php

When user try to come at site using any URL like:

1)www.domain.com/xyz

2)www.domain.com/abc

3)www.domain.com/apple

4)www.domain.com/123

5)www.domain.com/hello

Whatever random text at the end of the URL.

I want .htaccess code which redirects those URL to www.domain.com/index.php

index.php contain code to get data using GET method so the last string of URL needs to get in index.php file.

RewriteEngine on
RewriteRule ^(.*)$ http://www.example.com/index.php?parameter=$1

I tried this code but it goes in infinite redirect. I want to stop loop while parameter found.

Upvotes: 0

Views: 179

Answers (1)

Sorix
Sorix

Reputation: 918

You should be redirecting to a relative address (assuming that index.php is on the same domain). Also, you need to exclude existing files:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [QSA,L]

Upvotes: 2

Related Questions