双参数 URL 重写 [英] Double Parameter URL Rewrite

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

问题描述

我有以下带有双参数的 URL,并且第一次想进行双参数重写.

I have the following URL with double parameters and for the first time would like to do double parameter rewrite.

我的网址:http://localhost/b2b/post?post_id=1&post_subject=test

我想将其重写为:http://localhost/b2b/post/post_id/1/post_subject/test

我的 .htaccess 是:

My .htaccess is:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_METHOD}  !=POST
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,L,NC]
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^ %{REQUEST_URI}.php [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

<Files ~ "^(.*)\.(inc|tpl|sql)$">
    Order deny,allow
    Deny from all
</Files>

推荐答案

你应该只写:

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^post/([a-z0-9-_]+)/([a-z0-9-_]+)/([a-z0-9-_]+)/([a-z0-9-_]+)$  /post.php?$1=$2&$3=$4 [L]

这篇关于双参数 URL 重写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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