假设我有5页(index.php
,about.php
,portfolio.php
,gallery.php
,contact.php
)。使用5页的mod-Rewrite(通配符子域)
假设ID为1
。
原始URL是:
www.domain.com/folder/index.php?id=1
, www.domain.com/folder/about.php?id=1
等等...
现在,我想将其更改为:
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="" >
如果mod-rewrite可能会转到about.php
?
非常感谢你:DI感谢您的帮助:d
编辑
还有一两件事,我的通配符子域文件夹是public_html/folder/
该解决方案通过Anubhava
使用子域代码编辑:
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文件放在页面所在的目录中。
如果id改变了怎么办?假设它变成了'2'。以及如何重写子域'1.domain.com'?谢谢你的回答:D – 2013-02-14 09:26:03
哦,没有意识到你想要在'1.domain.com'中重写URL,现在请看编辑答案。如果你的ID改变了,那么你只需要改变RewriteRule线。 – anubhava 2013-02-14 09:33:31
我现在试试看:D谢谢:D – 2013-02-14 09:36:48