[英]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.