。htaccess重写条件/规则并隐藏url参数

问题描述 投票:0回答:2

我的根目录中有一个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/index.php?country=eu&lang=en

但是我想要这样-> http://example.com/eu-en

htaccess中有没有办法做到这一点?

apache .htaccess mod-rewrite url-rewriting url-parameters
2个回答
0
投票

尝试以下,

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)-([^/]+)$ index.php?country=$1&lang=$2 [QSA]

-1
投票

您需要附加[QSA](附加查询字符串)标签。尝试

RewriteEngine on

RewriteRule ^([a-z]{2,2})/([a-zA-Z0-9_-]+)$ index.php?lang=$1&page=$2 [QSA]

请参见http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html

© www.soinside.com 2019 - 2024. All rights reserved.