我觉得这应该是一个简单的解决方案,但我正在努力把它做好。我有网址:
-
http://www.testing.com/toursgbr/my-post
-
http://www.testing.com/toursgbr/my-post-2
我需要将URL重写为:
-
http://www.testing.com/tours/gbr/my-post
-
http://www.testing.com/tours/gbr/my-post-2
我做到了以下几点:
RewriteRule ^toursgbr/(.*) /tours/gbr/$1 [L]
这是当前htaccess文件中的内容:
RewriteEngine on
ErrorDocument 404 http://www.ausweb.com.au/web-hosting
AddHandler server-parsed html
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
RewriteCond %{HTTP_HOST} ^seabreezepark.com.au$ [OR]
RewriteCond %{HTTP_HOST} ^www.seabreezepark.com.au$
RewriteRule ^/?$ "http://theseabreezepark.com.au/" [R=301,L]
RewriteRule ^toursgbr/(.+)$ /tours/gbr/$1 [NC,L]
但很快就没有进展。我只想查找单词"toursgbr",并将其更改为"tours/gbr"。
将以下代码放在根.htaccess
文件中:
RewriteEngine on
RewriteBase /
RewriteCond %{THE_REQUEST} !s/+tours/gbr/ [NC]
# the above line will exclude any request having tours/gbr/ from the follwoing rule.
RewriteRule ^toursgbr/(.*)$ tours/gbr/$1 [R=302,L,NE]
# the above line will change any requested url having toursgbr/ to be tours/gbr/ temporary
# and you can change it to permanent by changing [R=302,L,NE] to [R=301,L,NE]
# but check the code as it is first then change it
RewriteRule ^tours/gbr/(.*)$ toursgbr/$1 [L,NC]
# the above line will internally map any request having tours/gbr/ to its original path
尝试:
RewriteRule ^toursgbr/(.+)$ /tours/gbr/$1 [NC,L]
如果您想在不更改浏览器中的url的情况下将/toursgbr/foo
内部重定向到/tours/gbr/foo
,请不要在重写目标中使用完整的url。
您更正的htaccess:
ErrorDocument 404 http://www.ausweb.com.au/web-hosting
AddHandler server-parsed html
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^(www.)?seabreezepark.com.au$
RewriteRule ^/?$ http://theseabreezepark.com.au/ [L,R=301]
RewriteRule ^toursgbr/(.+)$ /tours/gbr/$1 [NC,L]
# BEGIN WordPress
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]