dragon7713 2018-07-24 13:12
浏览 43

Mod_rewrite不在localhost上的子目录上工作

I have this folder system:

localhost/websites/2018/mywebsite

And there I have this file:

products.php

so the full route I type in my browser to access it is:

localhost/websites/2018/mywebsite/products.php

Now, I'm trying to use mod_rewrite to get this:

products.php?cat1=a&cat2=b&cat3=c

into this:

shop/a/b/c

So the full url would be:

localhost/websites/2018/mywebsite/shop/a/b/c

I tried putting the .htaccess in here:

localhost/websites/2018/mywebsite

with this code:

RewriteEngine On
RewriteRule ^shop/([^/]*)/([^/]*)/([^/]*)$ /products.php?cat1=$1&cat2=$2&cat3=$3 [L]

But when I go to

localhost/websites/2018/mywebsite/shop/

I get a 404. I think it has to do with the directory tree because when I upload it to the website (root directory) it works fine.

Edit: I tried using

RewriteBase localhost/websites/2018/mywebsite

And some variations but it didn't work. It threw 500 server error.

  • 写回答

1条回答 默认 最新

  • douyi3760 2018-07-24 13:47
    关注

    You would need to use %{QUERY_STRING} for this to work. Try something like the following:

    RewriteEngine On
    RewriteCond %{QUERY_STRING} cat1=(.+)&cat2=(.+)&cat3=(.+)$ [NC]
    RewriteRule ^ /shop/%1/%2/%3/? [R=301,L,NE]
    

    This grabs each of your variables and then rewrites /shop/a/b/c onto the end of your URL. The use of ? is there to stop the original query from appearing on the end of the URL.

    Make sure you clear your cache before testing this.

    评论

报告相同问题?

悬赏问题

  • ¥15 基于单片机的靶位控制系统
  • ¥15 AT89C51控制8位八段数码管显示时钟。
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错