简体   繁体   English

htaccess mod_rewrite条件和参数

[英]Htaccess mod_rewrite conditions and parameters

i need some help regarding rewrite rules of .htaccess, and some of the regular expressions there. 我需要有关.htaccess重写规则的帮助,以及那里的一些正则表达式。

i alredy have some rewrite rules definitions in htaccess, so if i call html file, it is executed as php. 我已经在htaccess中有一些重写规则定义,所以如果我调用html文件,它将作为php执行。

all i need now is if i open in browser like: 我现在需要的只是如果在浏览器中打开,例如:

http://mydomain.com/some-string/12345.html http://mydomain.com/some-string/12345.html

to call file article.php?id=12345 调用文件article.php?id = 12345

(id value can only be integer) (id值只能是整数)

if you can help he how to achieve this... 如果可以帮助他如何实现这一目标...

thank you in advance! 先感谢您!

You can achieve that by using the following code: 您可以使用以下代码来实现:

RewriteEngine On

RewriteRule ^some-string\/([0-9]*)\.html$ article.php?id=$1

Based on @Michiel answer: 基于@Michiel的答案:

RewriteEngine On

RewriteRule ^([a-z\-]+)\/([0-9]*)\.html$ article.php?id=$2 [NC,L]

This will catch (lower-case letters and hyphens)/(numbers).html and redirect to article.php?id=numbers. 这将捕获(小写字母和连字符)/(numbers).html并重定向到article.php?id = numbers。 ie this will now catch cars/13.html, mens-shorts/27.html, etc. 即现在将捕获cars / 13.html,mens-shorts / 27.html等。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM