如何在Apache服务器FreeBSD 8.1上创建模式_重写规则

如何在Apache服务器FreeBSD 8.1上创建模式_重写规则,apache,mod-rewrite,url-rewriting,freebsd,bsd,Apache,Mod Rewrite,Url Rewriting,Freebsd,Bsd,我正在FreeBSD 8.1上运行apache 2.2.25版的服务器上工作。 假设我有以下url:this.domain.com/html/folder/index.php 我想把它改写成这样:this.domain.com/index 我将如何具体创建重写规则?我应该在httpd.conf文件或.htaccess文件中创建重写规则,还是这并不重要? 还有,有没有办法将域名“this.domain.com”改成其他名称 假设,您希望用户输入较短的urlthis.domain.com/index

我正在FreeBSD 8.1上运行apache 2.2.25版的服务器上工作。 假设我有以下url:this.domain.com/html/folder/index.php 我想把它改写成这样:this.domain.com/index

我将如何具体创建重写规则?我应该在httpd.conf文件或.htaccess文件中创建重写规则,还是这并不重要?
还有,有没有办法将域名“this.domain.com”改成其他名称

假设,您希望用户输入较短的url
this.domain.com/index
,并在
this.domain.com/html/folder/index.php提供php服务;将以下规则添加到根目录下的
.htaccess

Options +FollowSymLinks -MultiViews
RewriteEngine on
RewriteBase /

RewriteCond %{HTTP_HOST} ^this\.domain\.com$ [NC]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/?$ html/folder/$1.php [L]
我不知道你把域名改成其他域名是什么意思
this.domain.com
可以更改为
that.domain.com
addon domain.com
,但只有当它们的DNS指向同一服务器(以服务共享内容)时才有意义。否则,它就像外部重定向到其他站点

RewriteCond %{HTTP_HOST} ^this\.domain\.com$ [NC]
RewriteRule ^(.*)$ http://that.domain.com/$1 [R=301,L]
试试这个

RewriteRule ^/index$ /html/folder/index.php [PT]