dsf12313
2013-12-27 20:25
浏览 89
已采纳

使用.htaccess重写多个URL

I have below code in my .htaccess file, located in "root/mosaicin/" directory.,

Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /mosaicin/

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]

RewriteRule ^(download-sample-papers|album|results|testimonials)/([^/]+)/?$ /$1.php?url=$2 [NC,QSA,L]

I want to rewrite my url www.domain.com/mosaicin/album.php/NID/ to domain.com/mosaicin/album/NID/ Same for other pages listed in rule (results,testimonials etc.)

Sample code in my album.php file is like

<?php
$cid = NULL;
$url = new SimpleUrl('/mosaicin/');
if($url->segment(2) == FALSE)
    $cname = 'NID';
else
    $cname = $url->segment(2);
$cname = urldecode($cname);
$ccsql = "SELECT courseid,cname FROM courses WHERE cname='".$cname."'";
$csql = $obj->select($ccsql);
if(count($csql)>0)
$cid = $csql[0]['courseid'];
?>

After getting courseid my code works to list items related to particular course. Currently when I go to page tplabs.in/mosaicin/album.php/NID everything works fine, but with link below tplabs.in/mosaicin/album/NID it gives 404 error.

Please help, Thanks in advance.

图片转代码服务由CSDN问答提供 功能建议

我的.htaccess文件中有以下代码,位于“root / mosaicin /”目录中。,

 选项+ FollowSymLinks -MultiViews 
RewriteEngine On 
RewriteBase / mosaicin / 
 
RewriteCond%{REQUEST_FILENAME} -f [OR] 
RewriteCond%{REQUEST_FILENAME} -d 
RewriteRule ^  -  [  L] 
 
RewriteRule ^(download-sample-papers | album | results | testimonials)/([^ /] +)/?$ /$1.php?url=$2 [NC,QSA,L] 
   
 
 

我想将我的网址www.domain.com/mosaicin/album.php/NID/重写为domain.com/mosaicin/album/NID/ Same,列出其他网页 在规则(结果,推荐等)中

我的album.php文件中的示例代码类似于

 &lt;?php 
  $ cid = NULL; 
 $ url = new SimpleUrl('/ mosaicin /'); 
if($ url-&gt; segment(2)== FALSE)
 $ cname ='NID'; 
else 
 $  cname = $ url-&gt; segment(2); 
 $ cname = urldecode($ cname); 
 $ ccsql =“SELECT courseid,cname FROM courses WHERE cname ='”。$ cname。“'”; 
  $ csql = $ obj-&gt; select($ ccsql); 
if(count($ csql)&gt; 0)
  $ cid = $ csql [0] ['courseid']; 
?&gt; 
   
 
 

获取courseid后,我的代码将列出与特定课程相关的项目。 目前,当我去页面 tplabs.in/mosaicin/album.php/NID一切正常,但链接下面的 tplabs.in/mosaicin/album/NID它给出404错误。

请帮忙, 提前谢谢。

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

  • dongyi1982 2013-12-28 15:20
    最佳回答

    Try these rules in your DOCUMENT_ROOT/.htaccess file:

    Options +FollowSymLinks -MultiViews
    RewriteEngine On
    RewriteBase /mosaicin/
    
    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^ - [L]
    
    RewriteRule ^(download-sample-papers|album|results|testimonials)/([^/]+)/?$ $1.php?url=$2 [NC,QSA,L]
    
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题