在ubuntu下写apache rewrite

首先确保你的apache已经装好了。

接着这样sudo ln -s /etc/apache2/mods-available/rewrite.load  /etc/apache2/mods-enabled/rewrite.load使得rewrite

模块为加载模块。这里涉及到一个available和enable的关系,前者为可用,后者为已经加载开始用的。ok?

 

我手里有一个网站,在apache根目录的/var/www下有一个baituan文件夹,此时在baituan文件夹下新建一个文件为.htaccess,在里面填写内容

 

RewriteEngine on
RewriteBase   /baituan/
RewriteRule ^pic/(\d)+/?& pic.php?a=$1 
RewriteRule ^club/?$ club.php?a=index
RewriteRule ^club/register/?$ club.php?a=register
RewriteRule ^club/login/?$ club.php?a=login
RewriteRule ^club/(\w)+/?$ club.php?a=$1&b=home
RewriteRule ^club/(\w)+/(\w)+/?$ club.php?a=$1&b=$2
RewriteRule ^club/(\w)+/(\w)+/(\w)+/?$ club.php?a=$1&b=$2&c=$3
RewriteRule ^actv/?$ actv.php?a=index
RewriteRule ^actv/(\w)+/create/?$ actv.php?a=$1&b=create
RewriteRule ^actv/(\w)+/(\w)+/?$ actv.php?a=$1&b=$2&c=home
RewriteRule ^actv/(\w)+/(\w)+/(\w)+/?$ actv.php?a=$1&b=$2&c=$3

 

 

接着我打算访问一个叫localhost/baituan/club/register的网页,它的确转发到了,但是那个get参数也就是a=register没有转发过去。我查了好久,不知所措。后来在网上看到一篇帖子。

http://serverfault.com/questions/60/mod-rewrite-does-not-forward-get-parameters

找到了解决方法。这里设计到一个multiview的问题

 

The effect of MultiViews is as follows: if the server receives a request for /some/dir/foo , if /some/dir has MultiViews enabled, and /some/dir/foo does not exist, then the server reads the directory looking for files named foo.*, and effectively fakes up a type map which names all those files, assigning them the same media types and content-encodings it would have if the client had asked for one of them by name. It then chooses the best match to the client's requirements.

这里是一个apache negotiation的问题。

举个例子,我在baituan下新建一个test.html

然后lcoalhost/baituan/test会自动请求到 test.html,这就是multiview。至于为什么这里会出现这个问题,我也不懂。

 

 

 

现在 sudo gedit /etc/apache2/sites-enabled/000-default

 

发现这里写着

    <Directory /var/www/baituan_temp/>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
    </Directory>

 

果断把MultiViews去掉,重启apache,问题解决。

 

 

 

 

 

你可能感兴趣的:(apache,C++,c,PHP,ubuntu)