htaccess的mod_rewrite的解释htaccess、mod_rewrite

2023-09-02 00:36:43 作者:云淡风轻

我一直试图让这个mod重写的事情了。基本上我想要的:

I've been trying to get this mod rewrite thing down. Basically I want:

removed.com/WineGlass/Vin.php removed.com/Chandelier/Auto.php

要被翻译成:

removed.com/news.php?post=Vin.php&cat=WineGlass removed.com/news.php?post=Auto.php&cat=Chandelier

到目前为止,我有:

Options -Multiviews
Options +FollowSymLinks  
RewriteEngine On  

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^/(.*)/(w+.php)$ ./news.php?cat=$1&post=$2

我对正在发生的事情的理解是,应该试图确定该文件是否存在,如果没有,请检查其是否符合图案。如果它满足的模式,就应该重写URL的一个期望。

My understanding of what is going on is that it should be attempting to determine if the file exists and if it does not, check to see if it meets the patter. If it meets the pattern, it should rewrite the url to the one desired.

在我使用GoDaddy.com是我的主人,我发现在互联网上很多帖子 这表明-Multiviews是必要的。 在确切的错误是:所请求的URL /poz/WineGlass/Vin.php不 在此服务器上找到。 的根/删除/而这正是news.php休息 在我以前regexr.com测试常规的前pression: http://regexr.com?37s5e 奖励:我尝试了几种方法来排除在上面的例子中最后浏览的网址,但无法。如果你能帮助,我将非常感激。 I use GoDaddy.com as my host and I found many posts on the internet suggesting that -Multiviews was required. The exact error is: The requested URL /poz/WineGlass/Vin.php was not found on this server. the root is /removed/ and that is where news.php rests I used regexr.com to test the regular expression: http://regexr.com?37s5e Bonus: I tried several ways to exclude the last URL in the example above but was unable to. If you can help with that, I would be very greatful.

推荐答案

DOCUMENT_ROOT /的.htaccess 文件中使用这个规则:

Use this rule in your DOCUMENT_ROOT/.htaccess file:

Options +FollowSymLinks -Multiviews
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/([^.]+.php)$ /news.php?cat=$1&post=$2 [L,QSA]