【问题标题】:.htaccess redirect directly after domainname.htaccess 直接在域名后重定向
【发布时间】:2020-07-25 13:44:49
【问题描述】:

我希望如果用户输入www.example.com/article-title,它会从www.example.com/index.php?title=article-title 获取数据。现在它只有在用户输入www.example.com/article/article-title 时才有效。我想删除那个article/

这是我现在在 .htaccess 文件中的内容:

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-d

RewriteCond %{REQUEST_FILENAME}\.php -f

RewriteRule ^(.*)$ $1.php [NC]

RewriteRule ^article/([0-9a-zA-Z]+) index.php?title=$1 [NC,L]

如果我从 .htaccess 文件的最后一行删除 article/,它根本不起作用。

$1 应该是article-title,但如果我删除article/$1 将变为index

有谁知道我可以如何更改 .htaccess 以让用户输入www.example.com/article-title

【问题讨论】:

    标签: php .htaccess url


    【解决方案1】:

    你只需要

    RewriteEngine on
    RewriteRule ^(.*)$ index.php?title=$1 [NC]
    

    here 测试

    input: https://www.example.com/article-title
    output: https://www.example.com/index.php?title=article-title
    

    但是我想这实际上是您真正想要的,因为从外观上看,您并没有锁定重定向,而是类似:

    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
    

    然后在index.php 文件中,您必须“操作”请求的网址

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-08-19
      • 1970-01-01
      • 2011-02-12
      • 1970-01-01
      • 1970-01-01
      • 2011-09-23
      • 2019-06-09
      • 2018-02-05
      相关资源
      最近更新 更多