开发者

(curiosity) .htaccess RewriteCond directive

I want to know what following code is doing in .htaccess file

RewriteEngine On
RewriteCond %{REQUEST_URI} !(swf|thumbs|index.php|template.php)
RewriteRule ^([^/\.]+).php?$ template.php?cat=开发者_如何学运维$1 [L,QSA]

Thanks in advance....


To answer the question about what the regexp actually means (as per my comment on the original answer above):

Each part in order:

^ - start of line

() - the grouping that $1 represents

[^/\.] - any character that is not / or a literal .

+ - more than one of the above character class

.php - obvious (though the . should be escaped, so it should be \.php)

? - unescaped in a regexp means 0 or 1 of the previous character

$ - end of line.

You'd probably be best off reading some regexp tutorials such as: http://www.regular-expressions.info/tutorial.html


If the request uri does not contain "swf", "thumbs" and so on

RewriteCond %{REQUEST_URI} !(swf|thumbs|index.php|template.php)

make /template.php?cat=etc out of /etc.php

RewriteRule ^([^/\.]+).php?$ template.php?cat=$1 [L,QSA]

L = "last rule" and QSA = append any existing query string to the newly created target uri.


The first line turns on the rewrite engine

The second line says "if the request uri doesn't contain swf or thumbs or index.php...

The third line will only be executed if line 2 was true (i.e. the URL didn't contain any of those strings). It will rewrite a URL like /123.php? to template.php?cat=123. The rewrite is internal so the user will just see the /123.php in their browser window.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜