[英]htaccess redirect and rewrite not redirecting to a URL
I am new to htaccess redirect and rewrite. 我是htaccess重定向和重写的新手。 I have converted the following url 我已经转换了以下网址
example.in/celeb_gallery.php?celeb_id=1
as 如
example.in/celebrity/1
by the follwing htaccess code example.in/celebrity/1
通过以下htaccess代码
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 为了再次获得celeb_id
的值,我在htaccess文件中添加了celeb_id
代码
RewriteRule ^celebrity/([^-]+)$ /celeb_gallery.php?celeb_id=$1 [L]
I uploaded the htaccess file. 我上传了htaccess文件。 when the url example.in/celeb_gallery.php?celeb_id=1
is trigerred, it changes as example.in/celebrity/1
in the address bar. 触发网址example.in/celeb_gallery.php?celeb_id=1
时,地址栏中的网址将更改为example.in/celebrity/1
。
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
. 但是该网页显示错误。 This Webpage has a direct loop
在Chrome中This Webpage has a direct loop
,而在Firefox中则显示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. 该示例工作sample.php文件仅包含以下代码:其工作无需任何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. celeb_id传入了celeb_gallery.php文件,但是我认为它没有打开任何样式表。 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'); ?>
<?php include('common/css_js.php'); ?>
and its not working i think. <?php include('common/css_js.php'); ?>
和它不工作,我认为。
If you want to redirect calls to example.in/celeb_gallery.php?celeb_id=1
to example.in/celebrity/1
you just need : 如果您想example.in/celeb_gallery.php?celeb_id=1
example.in/celebrity/1
呼叫重定向到example.in/celeb_gallery.php?celeb_id=1
, example.in/celebrity/1
需要:
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
但如果你想打电话到URL像example.in/celebrity/1
成为像通话过程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 如果匹配,则[L]标志将使htaccess停止处理其他规则
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.