.htaccess正则表达式有些麻烦

时间:2014-12-21 20:16:48

标签: regex .htaccess

您好我正在尝试使用重写引擎创建一个.htaccess,但是我无法找到正常的表达式来使其工作,实际上我已经在使用它几天了。所以我有两种类型的php文件,如:

  • list.php的
  • users.php

和其他带有1个参数的页面,总是具有相同的名称

  • user.php的?p = 1时
  • action.php的?p = 1时

所有这些都在同一个文件夹中: localholst / MY_DIR /管理/

所以我想制作一个RewriteRule来执行以下操作:

  • localholst / my_dir / admin / actions => localholst / my_dir / admin / actions.php
  • localholst / my_dir / admin / user / 1 => localholst / MY_DIR /管理/ user.php的P = 1

我的.htaccess现在是:

RewriteEngine on 
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC]

1 个答案:

答案 0 :(得分:0)

.htaccess目录的admin/中使用它:

RewriteEngine on 
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]

RewriteRule ^user/(.+)$ user.php?p=$1 [NC,L]
RewriteRule ^([^.]+)/?$ $1.php [NC,L]
相关问题