更新时间:2023-02-24 10:54:51
您可以尝试以下方式:
+ FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteCond%{REQUEST_URI} ^ / computers /([^ - ] +) - 电脑/? [NC]
RewriteRule。*%1-computer? [R = 301,L]
永久重定向
http://www.mydomain.com/computers/anyname-computer
带或不带尾部斜杠。
To:
http://www.mydomain.com/anyname-电脑
字符串电脑
和电脑
假定是固定的,而任何
被假定为可变的。
传入的URL结构要保留规则集工作:第一个文件夹 / computers
,后跟 / anyname-computer
。 p>
对于静默映射,从中删除
R = 301
[R = 301,L] code>
My directories are like:
http://www.mydomain.com/macbook-computer
http://www.mydomain.com/sony-computer
http://www.mydomain.com/lenovo-computer
I want to make that, if a user type computers/macbook-computer like:
http://www.mydomain.com/computers/macbook-computer
I want to display page which is : http://www.mydomain.com/macbook-computer
.
My restrictions are:
1. User must type /computers (segment 1)
2. String coming from computers/ must end with "computer". (segment 2)
How can I make this achieve in my .htaccess file?
You may try this:
Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^/computers/([^-]+)-computer/? [NC]
RewriteRule .* %1-computer? [R=301,L]
Redirects permanently
http://www.mydomain.com/computers/anyname-computer
with or without trailing slash.
To:
http://www.mydomain.com/anyname-computer
Strings computers
and computer
are assumed to be fixed, while anything
is assumed to be variable.
The incoming URL structure has to be kept for the rule-set to work: First folder /computers
followed by /anyname-computer
.
For silent mapping, remove R=301
from [R=301,L]