[英]htaccess redirect and rewrite not redirecting to a URL
我是htaccess重定向和重写的新手。 我已经转换了以下网址
example.in/celeb_gallery.php?celeb_id=1
如
example.in/celebrity/1
通过以下htaccess代码
Options +FollowSymlinks -Multiviews
RewriteEngine on
RewriteCond %{QUERY_STRING} ^celeb_id=(.*)$
RewriteRule ^celeb_gallery\.php$ /celebrity/%1? [R=301]
为了再次获得celeb_id
的值,我在htaccess文件中添加了celeb_id
代码
RewriteRule ^celebrity/([^-]+)$ /celeb_gallery.php?celeb_id=$1 [L]
我上传了htaccess文件。 触发网址example.in/celeb_gallery.php?celeb_id=1
时,地址栏中的网址将更改为example.in/celebrity/1
。
但是该网页显示错误。 This Webpage has a direct loop
在Chrome中This Webpage has a direct loop
,而在Firefox中则显示The page isn't redirecting properly
。 为什么它不起作用...?
该示例工作sample.php文件仅包含以下代码:其工作无需任何CSS。
<?php
echo "This is an sample page<br>";
echo "Celeb id:".$_REQUEST["celeb_id"];
echo "<br>";
?>
celeb_id传入了celeb_gallery.php文件,但是我认为它没有打开任何样式表。 代码在这里:
<?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>
样式表在<?php include('common/css_js.php'); ?>
<?php include('common/css_js.php'); ?>
和它不工作,我认为。
如果您想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]
但如果你想打电话到URL像example.in/celebrity/1
成为像通话过程example.in/celeb_gallery.php?celeb_id=1
所以你需要:
Options +FollowSymlinks -Multiviews
RewriteEngine on
RewriteRule ^celebrity/([\d]+)$ /celeb_gallery.php?celeb_id=$1 [L]
如果匹配,则[L]标志将使htaccess停止处理其他规则
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.