【发布时间】:2021-12-21 16:10:30
【问题描述】:
我在重写 URL 时遇到了一些问题
我想用我的.htaccess 将http://localhost:81/es/index.php 变成http://localhost:81/index.php?lengua=es,以帮助页面搜索引擎优化
这是我目前的.htaccess
<FilesMatch ".*\.(log|ini|htaccess)$">
deny from all
</FilesMatch>
Options -Indexes
RewriteEngine On
RewriteBase /
FallbackResource "index.php"
RewriteRule ^(en|es|pt)?/?(.*)?$ $2?idioma=$1 [QSA,L]
我已经检查过它们是否与 htaccess tester 一起工作并且它们按预期工作,但是当我浏览页面时它显示“找不到文件”。错误(我有index.php,我没有es/index.php)
由于我的输出 URL 是 http://localhost:81/index.php?lengua=es 我不明白为什么它不起作用
【问题讨论】:
-
您服务器的 error_log 文件中是否有这些请求的内容?
-
这条规则有什么作用吗?您的
.htaccess文件中还有其他指令吗?.htaccess是否启用覆盖? (是否启用了 mod_rewrite?) -
@StephenOstermiller 错误/apache 日志仅显示 404 错误错误日志输出:
code[Wed Nov 10 19:12:09.685194 2021] [proxy_fcgi:error] [pid 93:tid 140126253808360] [ client 172.24.0.1:41464] AH01071: Got error 'Primary script unknown', referer: localhost:81/index_traducciones.phpcode"/index_traducciones.php" 在 url 中不使用 /es 时完美运行 -
@StephenOstermiller 另外,重写规则是以前测试的保留,它不会改变结果,它仍然存在,因为我有时会在测试时更改规则的正则表达式(我只是评论了它,同样结果)
-
@MrWhite 和斯蒂芬一样,是以前测试的遗留物,我已经重写了 mod,我当前的完整 .htaccess 是:
拒绝所有 选项 -Indexes RewriteEngine On RewriteBase / FallbackResource "index.php" #RewriteCond %{REQUEST_URI} "\/en\/|\/es\/|\/pt\/" RewriteRule ^(en |es|pt)?/?(.*)?$ $2?idioma=$1 [QSA,L]
标签: apache .htaccess mod-rewrite