user6273094
user6273094

Reputation: 11

can't accessing $_GET when use .htaccess url rewrite

Now i want to cleanup my url with .htaccess here is my .htaccess code

RewriteEngine On RewriteRule ^([^/]*)/([^/]*)\.html$ /movies.php?id=$1&m=$2 [L]

its working fine

here is movies.php

<?php

if (!isset($_GET['m'])) {
    header("Location:index.php");
} else {
    $m = str_replace('_',' ',$_GET['m']);
}
echo $_GET['m'];

?>

the problem is it every time redirect the page to index.php

Upvotes: 0

Views: 84

Answers (2)

user6273094
user6273094

Reputation: 11

.htaccess should be

RewriteRule ^movies/([^/]+)/([^/]+)/?.html$ movies.php?m=$2&id=$1 [NC,L,QSA]

Upvotes: 1

kgommers
kgommers

Reputation: 74

Your code in the else part of the condition doesn't do anything except set the $m variable, but I don't see that being used somewhere else in your code. Did you maybe intend to do something like this?

<?php

if(!isset($_GET['m'])){  
    header("Location:index.php");  
} else {
    $m = str_replace('_',' ',$_GET['m']);  
}  

echo $m; ?>

Upvotes: 0

Related Questions