首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >部分域名的URL重写

部分域名的URL重写
EN

Stack Overflow用户
提问于 2016-05-10 04:37:54
回答 2查看 85关注 0票数 0

我觉得这应该是一个简单的解决办法,但我正在努力把它做好。我有网址:

  • 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

我了解到了以下几点:

代码语言:javascript
复制
RewriteRule ^toursgbr/(.*)   /tours\/gbr/$1   [L]

这就是当前htaccess文件中的内容:

代码语言:javascript
复制
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]

而且没有进展得很快。我只是想找一个词“旅游gbr”,并改为“旅游/gbr”的总结。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2016-05-11 01:44:48

将以下代码放在根.htaccess文件中:

代码语言:javascript
复制
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
票数 1
EN

Stack Overflow用户

发布于 2016-05-10 05:06:00

试着:

代码语言:javascript
复制
RewriteRule ^toursgbr/(.+)$ /tours/gbr/$1 [NC,L]

如果要在不更改浏览器中的url的情况下将/toursgbr/foo内部重定向到/tours/gbr/foo,请不要在重写目标中使用完整的url。

修正后的htaccess:

代码语言:javascript
复制
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]
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37129363

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档