php - 简单的 htaccess 技巧

标签 php .htaccess

我想制作 example.org/fish 并获取标签,但是,我的脚本获取了错误的标签。这是我的 htacess;

DirectoryIndex index.php

Options +FollowSymLinks
RewriteEngine On

RewriteRule ^(.*)$ index.php?tag=$1  

索引.php

echo $_REQUEST[tag]

输出

index.php

获取标签名称的正确方法是什么?

最佳答案

您需要从您的规则中禁止现有文件和目录,否则您的规则会第二次运行 index.php 作为 URI,并将 tag 参数作为 index。 php.

DirectoryIndex index.php
Options +FollowSymLinks
RewriteEngine On

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

关于php - 简单的 htaccess 技巧,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30161101/

相关文章:

php - Yii2 Gridview错误

regex - 使用新 url 结构从一个域 301 重定向到新域的正确方法?

apache - 如何仅在 HTTPS 上从 .htaccess 设置 HSTS header

php - 强制浏览器下载

apache - htaccess 在浏览器中启用目录 View 时添加密码

php - laravel,查询构建器,(或)查询未按预期工作的地方

php - PHP/MySQL 中的电子邮件发送器

PHP 表单仅在不为 null 时更新 MySql

.htaccess - htaccess filesmatch(htm|html|php) 除了两个特定文件?

php - 从 Mailgun 表单 Post PHP 中检索附件