简体   繁体   English

使用htaccess从网址中删除参数名称

[英]Remove parameter name from url using htaccess

I have the following url 我有以下网址

http://localhost/mybb/index.php?url=widgetboard/questions&step=1&id=1

which turns into the following url after applying rewrite rule 应用重写规则后将变为以下URL

http://localhost/mybb/widgetboard/questions/step/1/id/1

Is it possible to remove the 2 words ie "step" and "id" from the url and add .html at the very end of the url 是否可以从网址中删除2个字,即“ step”和“ id”,并在网址的最后添加.html

my code is 我的代码是

Options -MultiViews

# turn rewriting on
RewriteEngine On

# When using the script within a sub-folder, put this path here, like /mysubfolder/
# If your app is in the root of your web folder, then please delete this line or comment it out
RewriteBase /mybb/

RewriteRule ^(.+?)/(step)/([0-9]+)/(id)/([0-9]+)/?$ index.php?url=$1&$2=$3&$4=$5 [NC,L,QSA]

RewriteRule ^(.+?)/(category)/([0-9]+)/(answer)/([0-9]+)/?$ index.php?url=$1&$2=$3&$4=$5 [NC,L,QSA]

RewriteRule ^(.+?)/(step)/([0-9]+)/?$ index.php?url=$1&$2=$3 [NC,L,QSA]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+?)/?$ index.php?url=$1&$2=$3 [NC,L,QSA]

您可以RewriteBase /mybb/行下面插入此规则

RewriteRule ^([^/]+)/([^/]+)/([0-9]+)/([0-9]+)/?$ index.php?url=$1/$2&step=$3&id=$4 [L,QSA]

Change your second rule to: 将您的第二条规则更改为:

RewriteRule ^([^/]+)/([^/]+)/?$ index.php?step=$1&id=$2 [NC,L,QSA]

Then if a user clicks this url: domain.com/3/120 your PHP script will receive index.php?step=3&id=120 然后,如果用户单击以下URL: domain.com/3/120您的PHP脚本将收到index.php?step=3&id=120

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

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