dongliling6336 2011-04-14 21:32
浏览 29
已采纳

.htaccess重写重定向

I have some code which uses Rewrite engine in my .htaccess file and it specifies the directory for my SERPs. However when someone goes onto search/QUERY/ rather than search/QUERY/PAGE/ it displays a 404 error. Same with just search/.

I want it so that if someone just goes to search/QUERY/ that it redirects them to search/QUERY/1/ and for just search/ it redirects them to my homepage /. I have included a copy of my code below.

RewriteEngine on
RewriteRule ^search/([^/]+)/([^/]+)/?$ search.php?q=$1&category=web&d=$2

Can anyone help me with this problem?

Thanks in advance, Callum

  • 写回答

3条回答 默认 最新

  • dongmou5628 2011-04-15 12:09
    关注

    Try this code in your htaccess :

    RewriteEngine on
    RewriteRule ^search/?$ / [R=301,L]
    RewriteRule ^search/([^/]+)/?$ /search/$1/1/ [R=301,L]
    RewriteRule ^search/([^/]+)/([0-9]+)/?$ search.php?q=$1&category=web&d=$2 [NC,L]
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 如何使用canvas在图片上进行如下的标注,以下代码不起作用,如何修改
  • ¥15 Windows 系统cmd后提示“加载用户设置时遇到错误”
  • ¥50 vue router 动态路由问题
  • ¥15 关于#.net#的问题:End Function
  • ¥15 无法import pycausal
  • ¥15 VS2022创建MVC framework提示:预安装的程序包具有对缺少的注册表值的引用
  • ¥15 weditor无法连接模拟器Local server not started, start with?
  • ¥20 6-3 String类定义
  • ¥15 嵌入式--定时器使用
  • ¥20 51单片机学习中的问题