htaccess的mod_rewrite的解释 [英] .htaccess mod_rewrite explanation

查看:157
本文介绍了htaccess的mod_rewrite的解释的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直试图让这个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.

  • 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]

这篇关于htaccess的mod_rewrite的解释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆