Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.htaccess htaccess rewrite RegEx在参数之间添加静态值_.htaccess_Url_Mod Rewrite - Fatal编程技术网

.htaccess htaccess rewrite RegEx在参数之间添加静态值

.htaccess htaccess rewrite RegEx在参数之间添加静态值,.htaccess,url,mod-rewrite,.htaccess,Url,Mod Rewrite,我正试图用htaccess重写url。请求url长度是可变的。 它包括以下内容: http://[domain.com]/[countrycode]/[主类别]//[子类别]/[子类别]/[产品名称].html 当然,它也可以有更少的类别 另一个选项仅为产品页面,如: http://[domain.com]/[countrycode]/[product name].html 我想重写这些url,并在[countrycode]和url路径的其余部分之间添加一个静态值。另外,我想在每个重写URL的末

我正试图用htaccess重写url。请求url长度是可变的。 它包括以下内容:

http://[domain.com]/[countrycode]/[主类别]//[子类别]/[子类别]/[产品名称].html

当然,它也可以有更少的类别

另一个选项仅为产品页面,如: http://[domain.com]/[countrycode]/[product name].html

我想重写这些url,并在[countrycode]和url路径的其余部分之间添加一个静态值。另外,我想在每个重写URL的末尾将.html改为.aspx

我甚至可以重写一个只包含以下主要类别的url: 使用此访问权限:

RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteCond %{SERVER_PORT} ^80$
RewriteCond %{HTTP_HOST} ^(.*)example\.com [NC]
RewriteRule ^(.*)/(.*)$ https://example.com/$1/3/$2.aspx [R=301]
但是,如果url包含尾部斜杠或更多类别,则静态值(“3”)将添加到错误的位置

说清楚一点,我想要这个结构:

请求:

重写:


谢谢你的帮助

您可以在站点root.htaccess中使用此规则:

RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteCond %{SERVER_PORT} ^80$
RewriteCond %{HTTP_HOST} ^(.*)example\.com [NC]
RewriteRule ^(.*)/(.*)$ https://example.com/$1/3/$2.aspx [R=301]
RewriteEngine On

RewriteRule ^([a-z]{2})/(?!3/)(.+)\.html$ https://%{HTTP_HOST}/$1/3/$2.aspx [L,NC,NE,R=301]

编辑您的示例以满足我的需要。工作得很好。