2014-02-26 49 views
0

我是新的htaccess重定向和重写。我已经通过了follwing htaccess的代码htaccess重定向并重写不重定向到一个网址

Options +FollowSymlinks -Multiviews 
RewriteEngine on 
RewriteCond %{QUERY_STRING} ^celeb_id=(.*)$ 
RewriteRule ^celeb_gallery\.php$ /celebrity/%1? [R=301] 

转换以下网址

example.in/celeb_gallery.php?celeb_id=1

example.in/celebrity/1 再次获得的celeb_id值我在htaccess的添加followig码文件

RewriteRule ^celebrity/([^-]+)$ /celeb_gallery.php?celeb_id=$1 [L] 

我上传了htaccess文件。当网址example.in/celeb_gallery.php?celeb_id=1被激怒时,它会在地址栏中更改为example.in/celebrity/1

但是该网页在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'); ?>和它不工作,我认为。

+1

hi mukii您可以更改'RewriteRule ^(。*)$ /名人/([^ - ] +)$ /celeb_gallery.php?celeb_id=$1 [L]' –

+1

其显示内部服务器错误@ nu1_ww –

+0

can你试试这个吗? '选项+的FollowSymLinks -Multiviews RewriteEngine叙述上 的RewriteCond%{} REQUEST_FILENAME!-f 的RewriteCond%{} REQUEST_FILENAME!-d 的RewriteCond%{QUERY_STRING}^celeb_id =(。*)$ 重写规则^ celeb_gallery \ $ .PHP /名人/%1吗? [L]' –

回答

0

如果你想呼叫重定向到example.in/celeb_gallery.php?celeb_id=1example.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停止处理其他规则,如果规则是匹配

+0

它将'example.in/celeb_gallery.php?celeb_id = 1'更改为'example.in/celebrity/ 1“,但没有在网页中显示任何样式。该网址也不会更改为'celeb_id = 2,3,4etc'。网址更改仅适用于'celeb_id = 1'。 –

+0

如果您的CSS文件是通过相对路径进行缓冲的,请考虑从服务器的角度来看,当前文件夹是'example.in/celebrity /' – Geordie

+0

如何执行css文件...? –