javascript - URL 重写和获取参数未按预期工作

标签 javascript .htaccess mod-rewrite url-rewriting get

我有一个将参数发送到页面的表单。

但我也有 URL 重写

在 Htaccess 中我有

#mon chantier
RewriteRule mon-chantier/([^/]*)/([^/]*)\.html$ /index.php?page=mon-chantier&cp=$1&devis=$2 

当我发送表单时,URI 是

mon-chantier?devis=eree&cp=eeee

我需要的 URI 是

mon-chantier/eree/eeee.html

我尝试使用 JavaScript 来用输入值重写 URL,但如果有人禁用 JavaScript,它就不起作用。

最佳答案

您可以在 .htaccess 顶部使用此重定向规则:

RewriteEngine On

# mon-chantier?devis=eree&cp=eeee -> mon-chantier/eree/eeee.html
RewriteCond %{THE_REQUEST} /(mon-chantier)\?devis=([^\s&]+)&cp=([^\s&]+) [NC]
RewriteRule ^ /%1/%2/%3.html? [R=302,L,NE]

#mon chantier
RewriteRule ^mon-chantier/([^/]*)/([^/]*)\.html$ /index.php?page=mon-chantier&cp=$1&devis=$2 [L,QSA,NC]

关于javascript - URL 重写和获取参数未按预期工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37411269/

相关文章:

javascript - 我应该如何使用 bacon.js 保存多个值的运行总计?

regex - Apache - 重定向到相同的 URL 但附加了查询字符串

image - 将 WordPress 上传迁移到 Amazon S3

regex - Mod 重写正则表达式 : How to allow only one period between other characters?

php - 在 Wordpress(或 .htaccess)中创建 URL 别名

apache - htaccess 重定向陷入无限递归

javascript - 如何 float : top?

javascript - 使用 jquery sort 按两个数据属性对元素进行排序

javascript - 如何在java脚本中滚动到不断增长的ul的末尾

.htaccess - 如何编辑 htaccess 文件以将 http 域重写为 https?