php - .htaccess 中的语言参数未正确映射

标签 php regex .htaccess mod-rewrite redirect

我正在尝试重写此网址:

www.answerme.be/index.php?language=nl

www.answerme.be/nl

我已经做了一些研究,并且正在使用 generateit.net 中的工具。

我使用的表达式如下:

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

这应该有效吗?我收到 500 内部服务器 错误。

最佳答案

由于无限循环,您将得到 500。通过对 URI 中的 2 字符语言使用更好的正则表达式来修复此问题:

RewriteEngine On    
RewriteRule ^([a-z]{2})/?$ /index.php?language=$1 [L,QSA,NC]

关于php - .htaccess 中的语言参数未正确映射,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26572510/

相关文章:

PHP json_encode gapi (google analytics) 数组返回空值

python - 使用 str.contains 将字符串的一部分替换为分隔符

regex - Java正则表达式除最后一个字符外的所有字符

php - .htaccess 中的 RewriteRules 会影响站点的速度吗?

.htaccess - htaccess 规则不重定向到该文件夹

php - 查询返回错误数组 codeigniter

php - 使用 crontab 调度程序时,iOS 推送通知不起作用

php - MYSQL为200行生成5个随机字符(1-9,A-Z)

regex - 将 CamelCase 字符串转换为带下划线的大写

.htaccess - mod_rewrite GUI?