alexso
alexso

Reputation: 163

Homepage + redirect value from GET parameter

I need open file.php as index on my website. On homepage will be opened file.php without redirect to www.website.com/file.php

Second rewrite rule is redirect www.website.com/?id={id} to www.website.com/{id}

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ file.php?id=$1
RewriteRule ^$ /file.php

RewriteCond %{QUERY_STRING} ^(.*&)?id=([^&]*)(&.*)?$
RewriteRule ^ %{REQUEST_URI}?%1%2%3

Help me with htaccess code?

Upvotes: 0

Views: 20

Answers (1)

anubhava
anubhava

Reputation: 785098

You can have your rules like this:

RewriteEngine On

RewriteCond %{THE_REQUEST} \s/+\?id=([^\s&]+)\s [NC]
RewriteRule ^ /%1? [R=301,L,NE]

RewriteRule ^$ /file.php [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([\w-]+)/?$ file.php?id=$1 [L,QSA]

Upvotes: 1

Related Questions