【问题标题】:htaccess rewrite URL website.com/?collections%5B%5D=Pandemics to website.com/Pandemicshtaccess 重写 URL website.com/?collections%5B%5D=Pandemics 到 website.com/Pandemics
【发布时间】:2021-05-15 06:01:33
【问题描述】:

我正在尝试学习如何使用 htaccess 重写 URL,但发现它非常复杂。 我有一个基于提交表单显示不同内容的单页网站。 然后我使用参数 $_GET['collections'][0] 从 MySQL 数据库中获取数据并在网站上显示数据库内容。

http://website.com/?collections%5B%5D=Pandemics
http://website.com/?collections%5B%5D=American+Presidents

当用户提交表单并被重定向时,我希望 URL 看起来像这样:

http://website.com/Pandemics
http://website.com/American_Presidents

在这种情况下,用户在表单中选择了大流行病,并显示有关大流行病的信息。

我该如何实现?
我只知道我必须以某种方式使用 htaccess 来解决它,并且语法看起来像这样

RewriteEngine On
RewriteCond 
RewriteRule [Pattern] [Substitution] [Flags]

任何帮助将不胜感激!

【问题讨论】:

    标签: .htaccess mod-rewrite url-rewriting query-string friendly-url


    【解决方案1】:

    对于您显示的示例,您能否尝试以下操作。请确保在测试 URL 之前清除浏览器缓存。

    RewriteEngine ON
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)/?$ index.php?collections=$1 [L]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-10-10
      • 2015-06-24
      • 2013-04-29
      • 2016-05-27
      • 2020-10-08
      • 1970-01-01
      • 2020-07-12
      • 1970-01-01
      相关资源
      最近更新 更多