【问题标题】:How to fetch the slugname from url after rewrite the url重写url后如何从url中获取slugname
【发布时间】:2021-07-28 01:02:36
【问题描述】:

我有如下文件夹结构

-folder
--text
---index.php

我有一个如下所示的网址

https://example.com/folder/test/index.php?slug=slugname

我在 htaccess 中添加了以下代码来重写 URL。

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$ index.php?slug=$1 [QSA,L] 

所以现在我的网址是

https://example.com/folder/test/slugname

我必须在我的 php 页面上获取 slugname,我尝试了 echo $_REQUEST['slug'];echo $_GET['slug']; 但我得到了

slugname.php 

我只想要我的slugname

【问题讨论】:

  • @RavinderSingh13,请不要删除您的答案。清除缓存后就可以了

标签: apache .htaccess url mod-rewrite url-rewriting


【解决方案1】:

除了您的文件夹名为文件夹之外,请继续遵循 .htaccess 规则文件并尝试遵循规则。请确保在测试您的 URL 之前清除您的浏览器缓存。

RewriteEngine On
RewriteBase /folder/test/
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)/?$ index.php?slug=$1 [QSA,L] 

【讨论】:

  • 感谢您的回答,我只是想知道如何在重写url后在我的页面上获取slugname。
  • @user9437856,在使用这些规则之后,如果您在后端有正确的 url,那么您应该使用 php 代码获得正确的 slug 恕我直言,让我知道它是怎么回事。
  • 我也正在获取包含我的代码的页面。 URL 是 wotking,我必须获取 slugname 并传递给函数。并使用您的答案,我没有得到 slugname。
  • 我很抱歉我的不好,它在清除缓存后工作。感谢您的帮助和我的支持。
  • @user9437856,不用担心,加油,快乐学习。
猜你喜欢
  • 1970-01-01
  • 2017-02-02
  • 1970-01-01
  • 2020-10-22
  • 1970-01-01
  • 2013-07-20
  • 2011-03-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多