使用MOD-重写,5页(通配符子域) [英] Using mod-Rewrite with 5 pages (wildcard sub-domain)

查看:145
本文介绍了使用MOD-重写,5页(通配符子域)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

比方说,我有5页(的index.php about.php portfolio.php gallery.php contact.php )。

Let's say I got 5 pages (index.php, about.php, portfolio.php, gallery.php, contact.php).

让我们说的id是 1

原始URL是:

www.domain.com/folder/index.php?id=1 www.domain.com/folder/about.php?id=1 等等...

现在,我想将其更改为:

Now, I want to change it to :

1.domain.com/index 1.domain.com/about 1.domain.com/portfolio 1.domain.com/gallery 1.domain.com/contact

是否有可能与mod-rewrite?如果我在的index.php 页,最新的< A HREF => 的进入 about.php 如果mod-rewrite是可能的吗?

Is it possible with mod-rewrite ? And if I'm in the index.php page, whats the <a href="" > that goes to about.php if the mod-rewrite is possible?

非常感谢你:DI AP preciate您的帮助:D

Thank you very much :D I appreciate your help :D

修改

还有一件事,我的通配符子域文件夹的public_html /文件夹/

One more thing, My wildcard subdomain folder is public_html/folder/

解决方案通过 Anubhava

The Solution By Anubhava

编辑的子域codeS:

Edited with subdomain codes :

Options +FollowSymLinks -MultiViews

RewriteEngine On
RewriteBase /

# EDIT BY ANUBHAVA: to make http://1.domain.com/ load /about as default page
# Replace /about with any other page you want as default page
RewriteCond %{HTTP_HOST} ^1\.(domain\.com$ [NC]
RewriteRule ^$ /about [L]

RewriteCond %{HTTP_HOST} !^www.domain.com$ [NC]
RewriteCond %{HTTP_HOST} ^(www.)?([^.]+).domain.com$ [NC]
RewriteRule ^(index|about|portfolio|gallery|contact)/?$ /$1.php?id=%2 [L,NC,QSA]

请确保您的通配符子域目录中存放页面。也把你的.htaccess文件在该页面的目录。

Make sure your wildcard subdomain directory is where the pages are. Also put your .htaccess file in the directory where the pages are.

推荐答案

的httpd.conf 启用了mod_rewrite和.htaccess,然后把这个code在< $ C C>的.htaccess $ DOCUMENT_ROOT 目录下:

Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

# EDIT: to make http://1.domain.com/ load /about
RewriteCond %{HTTP_HOST} ^1\.(domain\.com$ [NC]
RewriteRule ^$ /about [L]

RewriteCond %{HTTP_HOST} ^1\.(domain\.com$ [NC]
RewriteRule ^(index|about|portfolio|gallery|contact)/?$ http://www.%1/folder/$1.php?id=1 [R=302,L,NC,QSA]

一旦到位创建这样的href链接:

Once that is in place create href links like this:

&LT; A HREF =htt​​p://1.domain.com/about&gt;关于美国和LT; / A&GT; &LT ; A HREF =htt​​p://1.domain.com/contact&GT;联系我们&LT; / A&GT;

这篇关于使用MOD-重写,5页(通配符子域)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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