【问题标题】:How to create mode_rewrite rule on Apache Server FreeBSD 8.1如何在 Apache Server FreeBSD 8.1 上创建 mode_rewrite 规则
【发布时间】:2013-08-15 22:46:33
【问题描述】:
我正在使用在 FreeBSD 8.1 上运行 apache 版本 2.2.25 的服务器。
假设我有以下网址:this.domain.com/html/folder/index.php
我想将其重写为:this.domain.com/index
我将如何具体创建重写规则?我应该在 httpd.conf 文件或 .htaccess 文件中创建重写规则,还是真的不重要?
另外,有没有办法将域名“this.domain.com”更改为其他名称?
【问题讨论】:
标签:
apache
mod-rewrite
url-rewriting
freebsd
bsd
【解决方案1】:
假设,您希望用户输入较短的 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]
【解决方案2】:
试试这个
RewriteRule ^/index$ /html/folder/index.php [PT]