【发布时间】:2020-04-03 07:52:28
【问题描述】:
我的根目录中有一个 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。
【问题讨论】:
标签: apache .htaccess mod-rewrite url-rewriting url-parameters