【问题标题】:.htaccess redirect with php slug.htaccess 使用 php slug 重定向
【发布时间】:2016-03-02 15:45:52
【问题描述】:

我的重写代码是:

RewriteEngine on
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(.*)index\.php($|\ |\?)
RewriteRule ^ /%1 [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php [NC,L]    

RewriteRule ^products/([a-z0-9_-]+)$ products.php?slug=$1

但是,这显示 products/slugname 重写规则的内部服务器错误。

我只在我的 slug id 中使用了小写字母、数字和破折号 (-)。

【问题讨论】:

  • htaccess 中还有其他规则吗?
  • 当我在根目录中创建一个 empty 文件夹 products 时,它似乎可以工作,它应该这样工作吗?
  • 是的,隐藏扩展的重写规则导致了这个问题。有没有办法可以在同一个 .htaccess 文件中同时使用两者
  • 您的文件结构如何? /foo/index.php 还是 /foo.php?
  • 它的 /filename.php

标签: .htaccess url-rewriting slug


【解决方案1】:

试试这个:

RewriteEngine on
RewriteCond %{THE_REQUEST} /([^.]+)\.php [NC]
RewriteRule ^ /%1 [R,L]

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

RewriteRule ^products/([a-z0-9_-]+)$ /products.php?slug=$1 [NC,L]

【讨论】:

  • 你的 htaccess 在 root 中吗?
  • 是的,它在根文件夹中,除了将 index.php 隐藏在索引文件的 url 中,其他一切都失败了。但是,我非常感谢你的帮助兄弟。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-07-28
  • 2019-07-10
  • 1970-01-01
  • 1970-01-01
  • 2021-04-01
  • 2018-07-15
  • 1970-01-01
相关资源
最近更新 更多