John Kariuki
John Kariuki

Reputation: 5724

.htaccess url rewrites in index.php and not profile.php

So I am pretty new to url rewritting and.htaccess in general. I would like to rewrite the url below

/rewrite/profile/karis/2

as

/rewrite/profile.php?name=karis&id=2

so the code I have for my .htaccess is

RewriteEngine on
RewriteRule ^profile profile.php

RewriteRule ^([a-zA-Z0-9_-]+)/([0-9]+)$ profile.php?name=$1&id=$2
RewriteRule ^([a-zA-Z0-9_-]+)/([0-9]+)/$ profile.php?name=$1&id=$2

So this works perfectly when I change everything to work for index.php but the same code does not work on profile.php.

The simple php code is

<?php
    if(isset($_GET['name']) && isset($_GET['id']))
    {
        echo "Hi ".$_GET['name'].", your id is ".$_GET['id'];   
    }
?>

Any Ideas why?

Upvotes: 0

Views: 91

Answers (1)

anubhava
anubhava

Reputation: 784918

Your rules can all be combined into one and first one is misplaced also. Try this in your /rewrite/.htaccess:

Options +FollowSymLinks -MultiViews
RewriteEngine on
RewriteBase /rewrite/

RewriteRule ^([\w-]+)/([0-9]+)/?$ profile.php?name=$1&id=$2 [L,QSA]

RewriteRule ^profile/?$ profile.php [L]

Upvotes: 1

Related Questions