部分域名的URL重写 [英] URL rewrite for part of domain name

查看:330
本文介绍了部分域名的URL重写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我认为这应该很容易解决,但是我正在努力将其正确完成. 我有网址:

I feel this should be an easy fix but I'm struggling to get it done right. I have the URL:

http://www.testing.com/toursgbr/my-post -2

我需要将URL重写为:

I need to rewrite the URL to:

http://www.testing.com/tours/gbr /my-post-2

我了解到以下信息:

RewriteRule ^toursgbr/(.*)   /tours\/gbr/$1   [L]

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

This is what's currently in the htaccess file:

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".

and got nowhere pretty fast. I just want to look for the word "toursgbr" and change it to "tours/gbr" in summary.

推荐答案

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

Put the Following code at root .htaccess file :

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

这篇关于部分域名的URL重写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆