使用.htaccess重写URL

时间:2013-12-24 06:16:48

标签: php regex .htaccess mod-rewrite url-rewriting

如何在 .htaccess 的帮助下使用网址重写来更改网址

以下是网址

FROM:

http://www.test.xyz.com/ab/web/pds/dispall/web/web-design

TO:

http://www.web.test.xyz.com/ab/web/pds/dispall/web-design

我想将第五个(第五个)参数用作子域。

谢谢!

1 个答案:

答案 0 :(得分:2)

将此代码放入DOCUMENT_ROOT/.htaccess文件中:

RewriteEngine On

RewriteCond %{HTTP_HOST} ^www\.test\.xyz\.com$ [NC]
RewriteCond %{REQUEST_URI} /pds/
RewriteRule ^[^/]+/[^/]+/[^/]+/[^/]+/([^/]+)/.*$ http://www.$1.test.xyz.com%{REQUEST_URI} [NE,R=301,L]