2010-05-15 202 views
0

有什么办法,我可以使用重写规则,以显示这些链接:重写规则问题

/articles_history.php

/articles_geography.php

/articles/history.html

/articles/geography.html

我创建在我的根目录下有一个.htacesss文件,并想通过在.htaccess文件中放置某种代码来知道上述内容是否可行。

回答

2
RewriteEngine On 
RewriteRule /articles/(.+)\.html /articles_$1.php [L,QSA] 
+0

它不工作 HTTP://localhost/yo/articles_history.php仍然是相同的。 – NegativeCrack 2010-05-15 19:55:10

+0

@NegativeCrack - 是的,PHP文件的直接URL仍然可以正常工作。 – 2010-05-15 19:56:24

+0

好了,其实我是想我的浏览器显示: HTTP://localhost/yo/articles_history.php AS HTTP://localhost/yo/articles/history.html 地址栏上。就是这样! 我将.htaccess文件放在“yo”文件夹中。 我现在要做什么? 感谢您的帮助:) – NegativeCrack 2010-05-15 19:59:13

0

试试这个在您的.htaccess:

RewriteEngine on 
RewriteRule ^article/([^/]+)\.html$ articles_$1.php [L] 

而对于任意输入:

RewriteEngine on 
RewriteRule ^([^/]+)/([^/]+)\.html$ $1_$2.php [L]