harikrishnan.n0077
harikrishnan.n0077

Reputation: 2087

How to redirect based on this condition using .htaccess?

Currently i am using the below .htaccess for removing the .php extension

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php

I want to show the page www.example.com/login.php when typing www.example.com/login and want to show www.example.com/profile=username when typing www.example.com/username

Any suggestion or answers thanks in advance

Upvotes: 0

Views: 358

Answers (2)

Felipe Alameda A
Felipe Alameda A

Reputation: 11809

Here is another option:

RewriteEngine On
RewriteCond %{REQUEST_URI} (.*)/([\w]+)\.php [NC]

#Select ONE of the following options and DELETE the others
# 1) Without redirection
RewriteRule .*  %1/%2 [L]

# 2) With temporary redirection
RewriteRule .*  %1/%2 [R,L]

# 3) With permanent redirection
RewriteRule .*  %1/%2 [R=301,L]

Select the rewrite rule accordingly.

Upvotes: 1

Talha Akbar
Talha Akbar

Reputation: 10040

http://www.9lessons.info/2009/11/pretty-urls-with-htaccess-file.html

RewriteEngine On
RewriteRule ^([a-zA-Z0-9_-]+)$ index.php?key=$1
RewriteRule ^([a-zA-Z0-9_-]+)/$ index.php?key=$1

<?php

$key=$_GET['key'];

if($key=='home')
{
include('home.php'); // Home page
}
else if($key=='login')
{
include('login.php'); // Login page
} 
else if($key=='terms')
{
include('terms.php'); // Terms page
}
else 
{
include('users.php'); // Users Gateway
}
?>

Upvotes: 2

Related Questions