如何编写二级域名跳转二级目录的伪静态或者php

WBOY
Release: 2016-06-23 13:39:55
Original
1856 people have browsed it

目前目的达到的代码

RewriteEngine OnRewriteCond %{HTTP_HOST} ^sell-meihualu.abc.com$ [NC]RewriteRule (.*) http://www\.abc\.com/sell/meihualu/$1 [R=301,NC,L]
Copy after login



如何把sell设置为变量A
meihualu设置为变量B
实现
A-B.abc.com
跳转到对应的
www.abc.com/A/B/


或者有没大神可以PHP文件解决
本人刚学没多久


回复讨论(解决方案)

你那是 301 跳转,不是伪静态
跳转后 url 就变了

这是我用的
RewriteCond %{HTTP_HOST} ^([^\.]+).tool.net$
RewriteRule ^(/?)(.*)$ /users/%1/$2 [PT,L]
令形如 blog.tool.net/index.php 的 url 定位到 users/blog/index.php
url 不变

同理,你的规则写作这样就可以了
RewriteCond %{HTTP_HOST} ^([a-z]+)-([a-z]+).abc.com$ [NC]
RewriteRule (.*) http://www\.abc\.com/%1/%2/$1 [R=301,NC,L]

不会只有 sell-meihualu.abc.com 这样一个二级域名吧?

感谢版主大大的回复。。

确实不止一条,单条的话 我会写死!

你那是 301 跳转,不是伪静态
跳转后 url 就变了

这是我用的
RewriteCond %{HTTP_HOST} ^([^\.]+).tool.net$
RewriteRule ^(/?)(.*)$ /users/%1/$2 [PT,L]
令形如 blog.tool.net/index.php 的 url 定位到 users/blog/index.php
url 不变

同理,你的规则写作这样就可以了
RewriteCond %{HTTP_HOST} ^([a-z]+)-([a-z]+).abc.com$ [NC]
RewriteRule (.*) http://www\.abc\.com/%1/%2/$1 [R=301,NC,L]

不会只有 sell-meihualu.abc.com 这样一个二级域名吧?




如果是IIS的httpd.ini

如何修改?

# Protect httpd.ini and httpd.parse.errors files# from accessing through HTTPRewriteCond Host: ([a-z0-9]+)-([a-z0-9]+)\.abc\.comRewriteRule (.*) http://www\.abc\.com/$1/$2/$3 [I,RP]
Copy after login

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!