apache - .htaccess 重写条件/规则并隐藏 url 参数
问题描述
我的根目录中有一个 htaccess。
我的文件路径http://example.com/folder1/folder2/index.php?country=eu&lang=en
我在 htaccess 中做了这个。
RewriteCond %{HTTP_HOST} ^(www.)?anothersite.com$
RewriteRule ^([^/]*)/([^/]*)$ /folder1/folder2/index.php?country=$1&lang=$2 [L]
RewriteRule ^([^/]*)$ /folder1/folder2/index.php [L]
看起来像这样
但我想要这样-> http://example.com/eu-en
有没有办法在 htaccess 中做到这一点?
编辑: 我必须使用重写条件,因为我重定向到文件夹取决于主机。
编辑 2:解决方案
RewriteCond %{HTTP_HOST} ^(www.)?anothersite.com$
RewriteRule ^([a-z]{2,2})-([a-zA-Z0-9_-]+)$ /folder1/folder2/index.php?country=$1&lang=$2 [QSA]
感谢答案,它现在正在工作。但在那之后我在网站上得到了 css 和 js 错误。然后我更改了css和js路径/folder1/folder2/css。
解决方案
试试下面,
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)-([^/]+)$ index.php?country=$1&lang=$2 [QSA]
推荐阅读
- r - r 根据灵活时间窗口内的出现次数过滤行
- r - Shiny的ActionButton没有响应
- wso2 - 在代理后面使用 Choreo 分析
- python - 在 Django 中处理多个请求
- intellij-idea - Intellij 意图“创建缺少的开关分支”不起作用
- sql - 如何批量插入平面文件使 Unicode 与越南语一起使用
- javascript - Web Audio API 无法将数据卸载到 .csv 文件中以构建图形?
- c# - 网络::ERR_NAME_NOT_RESOLVED 泊坞窗
- r - R 在 Linux 上自动执行脚本
- reactjs - TS2322:输入“承诺”
' 不可分配给类型 'string'