I am new to htaccess redirect and rewrite. I have converted the following url
example.in/celeb_gallery.php?celeb_id=1
as
example.in/celebrity/1
by the follwing htaccess code
Options +FollowSymlinks -Multiviews
RewriteEngine on
RewriteCond %{QUERY_STRING} ^celeb_id=(.*)$
RewriteRule ^celeb_gallery\.php$ /celebrity/%1? [R=301]
for again getting the value of celeb_id
i am adding the followig code in the htaccess file
RewriteRule ^celebrity/([^-]+)$ /celeb_gallery.php?celeb_id=$1 [L]
I uploaded the htaccess file. when the url example.in/celeb_gallery.php?celeb_id=1
is trigerred, it changes as example.in/celebrity/1
in the address bar.
But the webpage shows an error This Webpage has a direct loop
in Chrome and in firefox it shows The page isn't redirecting properly
. why its not working...?
The sample working sample.php file contains following code only : its working without any css.
<?php
echo "This is an sample page<br>";
echo "Celeb id:".$_REQUEST["celeb_id"];
echo "<br>";
?>
the celeb_id is passing in celeb_gallery.php file, but it does not opening any style sheets i think. and the code is here:
<?php include('cpanel/common/dbconnect.php');?>
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
<?php
$ncel = "SELECT * FROM celebrity WHERE cel_id = ".$_REQUEST['celeb_id']."";
$ncel_e = mysql_query($ncel);
$ncel_f = mysql_fetch_array($ncel_e)
?>
<title><?=$ncel_f['name']?> | Site Title</title>
<?php include('common/css_js.php'); ?>
</head>
The style Sheets are called in <?php include('common/css_js.php'); ?>
<?php include('common/css_js.php'); ?>
and its not working i think.
If you want to redirect calls to example.in/celeb_gallery.php?celeb_id=1
to example.in/celebrity/1
you just need :
Options +FollowSymlinks -Multiviews
RewriteEngine on
RewriteCond %{QUERY_STRING} ^celeb_id=([\d]+)$
RewriteRule ^celeb_gallery\.php$ /celebrity/%1 [L, R=301]
But if you want call to URL like example.in/celebrity/1
to be process like call to example.in/celeb_gallery.php?celeb_id=1
So you need :
Options +FollowSymlinks -Multiviews
RewriteEngine on
RewriteRule ^celebrity/([\d]+)$ /celeb_gallery.php?celeb_id=$1 [L]
The [L] flag will make the htaccess stop processing other rules if the rule is matched
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.