提问者:小点点

如何删除文件名


当前URL:http://broom.xyz/index.php?tag=C/santa

目标URL:http://broom.xyz/C/santa

注意:标记“C/santa”是单个动态值
它可以更改为“F/fanta”或“M/Manta”之类的任何内容。

我的代码:

RewriteEngine On
RewriteBase /

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-l

RewriteRule ^([^/]*)$ /index.php?tag=$1 [L]

此代码生成一个500内部服务器错误。以下是错误日志:

[Fri Apr07 13:33:10.469218 2017][core:警报][pid 4202][客户端47.11.122.64:52755] /var/www/html/workspace/broom/.htaccess:无效的命令'重写引擎',可能拼写错误或由服务器配置中未包含的模块定义[Fri Apr<--plhd-3/>][core:警报][pid 4185][客户端47.11.122.64:53076] /var/www/html/workspace/broom/.htaccess:无效的命令'ReWriteEngine',可能拼写错误或由服务器配置中未包含的模块定义


共1个答案

匿名用户

您的规则的模式与uri C/Santa不匹配,但与CSanta匹配。这是因为您在模式中排除了/ ^([^/]*) .您需要修复它,以便它可以接受uri中的任何字符。

将规则行替换为以下内容:

RewriteRule ^(.+)$ /index.php?tag=$1 [L]