YOYO的最新BLOG文章

Jul
02

这个方法真的是很牛x,我直接拷贝过来,改了一下域名和目录就直接能用了,网上很少有这么牛的文档,所以我也就直接转载过来了,什么都没改。

具体写法如下:

# .htaccess main domain to subfolder redirect
# Copy and paste the following code into the .htaccess file
# in the public_html folder of your hosting account
# make the changes to the file according to the instructions.

# Do not change this line.

RewriteEngine on

# Change yourdomain.com to be your main domain.

RewriteCond %{HTTP_HOST} ^(www.)?yourmaindomain.com$

# Change ’subfolder’ to be the folder you will use for your main domain.

RewriteCond %{REQUEST_URI} !^/subfolder/

# Don’t change this line.

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# Change ’subfolder’ to be the folder you will use for your main domain.

RewriteRule ^(.*)$ /subfolder/$1

# Change yourdomain.com to be your main domain again.
# Change ’subfolder’ to be the folder you will use for your main domain
# followed by / then the main file for your site, index.php, index.html, etc.

RewriteCond %{HTTP_HOST} ^(www.)?yourmaindomain.com$
RewriteRule ^(/)?$ subfolder/index.php [L]

文章来源:http://hi.baidu.com/chenjia14/blog/item/a9a9fc50b8a3f2501038c2a0.html

Tags: , ,
Posted in Server
Sep
16

绝大多数网站改版后都会面对一个令人很苦恼的问题,就是怎么让原来的地址可以正常访问,且和新改版后的网站能有机的结合在一起。

对于这个问题,比较好的解决办法是通过.htaccess文件的重定向来解决,而很多人不知道怎么来写.htaccess文件,尤其是里面的正则表达式,这里我仅简单说一下怎样通过.htaccess来实现旧地址到新地址的跳转,其他更深入的知识,以及正则表达式的知识,我会在以后的博文中讲解。

通过.htaccess调整我这里有两种方法:第一种是通过redirect来实现,代码是

Redirect 原地址 新地址

例如我在rssdiy上面的写法是

Redirect /show-1.html http://www.rssdiy.net/channel/1/

这和域名里面的url调整是一个效果的。第二种是通过RewriteRule来实现的,代码是

RewriteRule 原url规则 新url规则

注意这里是规则,可以用正则表达式。例如上面的地址也可以这样写

RewriteRule ^show-([0-9]+)\.html$ channel/$1/ [R]

阅读全文 ->

Tags: ,
Posted in Server, 刀光剑影