【问题标题】:htaccess url rewriting from request query to folder like and changing the php namehtaccess url从请求查询重写到文件夹,并更改php名称
【发布时间】:2021-09-13 14:25:24
【问题描述】:

如何在稍后在线托管的 localhost 上执行以下操作:

我有这个链接:

http://localhost/shops/shop.php?c=15

我想改写成http://localhost/shops/shop/15

htaccess是(放在C:\wamp\www\shops folder):

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/?RECIPES/(.*?)/?$ /single-product-details.php?=$1 [L]
RewriteRule ^/?SHOP/(.*?)/?$ /shop.php?=$1 [L]

【问题讨论】:

  • 请在您的问题中分享您尝试过的 htaccess 规则文件,谢谢。
  • RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^/?RECIPES/(.*?)/?$ /single-product-details.php?= $1 [L] RewriteRule ^/?SHOP/(.*?)/?$ /shop.php?=$1 [L]

标签: .htaccess redirect mod-rewrite url-rewriting friendly-url


【解决方案1】:

对于您展示的样品,请尝试遵循规则。将您的 htaccess 文件与商店文件夹(不在其中)一起放置。

请确保在测试您的 URL 之前清除您的浏览器缓存。

RewriteEngine ON
RewriteBase /shops/
##External redirect to friendly url.
RewriteCond %{THE_REQUEST} \s/shops/(shop)\.php\?c=(\d+)\s [NC]
RewriteRule ^ /%1/%2? [R=301,L]
##Internal rewrite to actual url/files.
RewriteRule ^([^/]*)/(.*)/? $1.php?c=$2 [QSA,L]

【讨论】:

  • 它没有用,仍然显示:localhost/iCook/shop.php?c=5
  • 从 apache 开启重写,我也清除了缓存
  • @AliElMenini,你点击的网址是什么?
  • @AliElMenini,好的,所以你想在浏览器中从 localhost/shops/shop.php?c=7 重定向到 localhost/shops/shop?请确认一次。
  • 我希望 localhost/shops/shop.php?c=7 像 localhost/shops/shop/7 一样
猜你喜欢
  • 1970-01-01
  • 2014-03-01
  • 2020-09-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-10-08
  • 1970-01-01
相关资源
最近更新 更多