aiden87
aiden87

Reputation: 969

How to redirect in .htaccess

This is my first time working with .htaccess and i'm absolutely clueless...

I need to create a .htaccess file, which would redirect from URL to another URL.

Let's say user types the following URL: http://localhost/htaccess_test/os/windows/8 ...when he does, he would get redirected to http://localhost/htaccess_test/os/windows/os.php?type=windows&version=8 .

I also need to create a os.php file, which lists values of the parameters in URL (type and version of operating system).

Any help will be much appreciated!

UPDATE

.htaccess

RewriteEngine on
RewriteRule ^os/([^/]+)/([^/]+)$ /os.php?type=$1&version=$2 [R=301,L]

os.php

<?php

if(isset($_GET['type']) && isset($_GET['version'])){

    echo "Tip OS: " . $_GET['type'] . "<br>";
    echo "Verzija OS: " . $_GET['version'] . "<br>";
}
?>

Upvotes: 1

Views: 55

Answers (1)

anubhava
anubhava

Reputation: 786291

Create this .htaccess in htaccess_test/ directory:

Options -MultiViews
RewriteEngine On

RewriteRule ^os/([\w-]+)/(\d+)/?$ os.php?type=$1&version=$2 [L,NC,QSA]

Assuming os.php exists in htaccess_test/os/windows/ directory

Upvotes: 1

Related Questions