如何使用htaccess文件传递参数

时间:2017-08-05 15:12:34

标签: php .htaccess

目前我的.htaccess文件内容

RewriteRule list/(.*)/(.*)/ list.php?catnm=$1&tnm=$2
RewriteRule list/(.*)/(.*) list.php?catnm=$1&tnm=$2

但是当我在

之间生成带有list关键字的url时,这是有效的
www.example.com/list/css/Introduction-of-CSS

转换为

www.example.com/list.php?catid=css&tid=Introduction-of-CSS 

在我的项目中,现在我生成的URL没有列表关键字

www.example.com/css/Introduction-of-CSS

我的.htaccess文件应该更改什么? 感谢

3 个答案:

答案 0 :(得分:1)

您可以使用:

RewriteEngine on 
Options -MultiViews
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^list/([^/]+)/([^/]+)/?$ list.php?catnm=$1&tnm=$2 [QSA,NC,L]

排除所有现有文件。
或者您可以使用:

RewriteEngine on 
Options -MultiViews
RewriteRule ^list/([0-9A-Z_]+)/([0-9A-Z_]+)/?$ list.php?catnm=$1&tnm=$2 [QSA,NC,L]

其中包含-的所有文件。

答案 1 :(得分:0)

你可以尝试

getDepthBufferHandle()

答案 2 :(得分:0)

把它放在.htaccess中:

  Options +FollowSymlinks

  RewriteEngine On

  RewriteRule ^(.*)$ http://small.me/?$1 [L]

  RewriteRule ^profile/([a-z0-9]+)$ friend.php?username=$1 [NC,L]
相关问题