如何做一个简单的Mod_Rewrite

时间:2013-10-29 23:17:14

标签: apache .htaccess mod-rewrite clean-urls

我只是想清理一下这样的网址:

/// FROM :
http://mydomain.com/about.php
http://mydomain.com/contact.php

/// TO:
http://mydomain.com/about
http://mydomain.com/contact

我的.htaccess文件:

 Options +FollowSymlinks
 RewriteEngine on


 RewriteRule ^about about.php [NC]  

错误:

Not Found

The requested URL /about was not found on this server.

这里有什么问题?

2 个答案:

答案 0 :(得分:0)

为避免无限循环,您可以在.htaccess中使用它:

Options +FollowSymlinks
RewriteEngine on

RewriteRule ^(about|contact)$ $1.php [NC,L]

[NC,L]可能很重要,应该通过

启用rewrite_mod
a2enmod rewrite

答案 1 :(得分:0)

似乎我必须禁用默认启用的multiviews

我的.htaccess:

Options +FollowSymLinks -Multiviews
RewriteEngine on

RewriteRule ^(about|contact)$ $1.php [NC,L]