【问题标题】:htaccess not rules with index and another page with paramhtaccess 不是带有索引的规则和带有参数的另一个页面
【发布时间】:2021-02-16 11:19:12
【问题描述】:

我在配置一个简单的 htaccess 时遇到问题,需要重写两个页面:索引和 page.php?param=valueparam

问题是这些规则中的一个正确,另一个不起作用。

这些是我需要的:

  • index.php -> mydomain.com/
  • page.php?param=valueparam -> mydomain.com/valueparam

我尝试了几个选项,但没有任何我想要的规则:

Options +FollowSymLinks 
Options -Indexes

php_value default_charset None
AddDefaultCharset utf-8

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^([0-9a-z_-]*)$ page.php?param=$1 [NC,L]

【问题讨论】:

  • 欢迎来到 SO 并感谢您在问题中发表您的努力。如果mydomain.com/valueparam 是您在浏览器中点击的链接,您能否告诉我们?您想在后端使用page.php?param=valueparam 服务哪个?

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


【解决方案1】:

仅基于您显示的示例,您能否尝试遵循 htaccess 规则文件,请确保在测试您的 URL 之前清除浏览器缓存。

RewriteEngine ON
##For index.php -> mydomain.com as per OP's first condition.
RewriteRule ^/?$ index.php [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(valueparam)/?$ page.php?param=$1 [NC,L]

【讨论】:

    猜你喜欢
    • 2012-01-03
    • 2018-08-14
    • 2013-11-10
    • 2018-06-27
    • 1970-01-01
    • 2023-03-29
    • 2016-12-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多