Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/284.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php write.htaccess重写网站URL多个参数_Php_.htaccess_Url Rewriting - Fatal编程技术网

Php write.htaccess重写网站URL多个参数

Php write.htaccess重写网站URL多个参数,php,.htaccess,url-rewriting,Php,.htaccess,Url Rewriting,我是.htaccess的新手,在重写一些URL时遇到了问题 我的网站是用php制作的,有两个参数:param1和param2。 URL看起来类似于: www.website.com/index.php?param1=12345678 www.website.com/index.php?param1=09876543 www.website.com/index.php?param2=abcdefgh www.website.com/index.php?param2=qwertzui 我想创建一

我是.htaccess的新手,在重写一些URL时遇到了问题

我的网站是用php制作的,有两个参数:param1和param2。 URL看起来类似于:

www.website.com/index.php?param1=12345678
www.website.com/index.php?param1=09876543

www.website.com/index.php?param2=abcdefgh
www.website.com/index.php?param2=qwertzui
我想创建一个.htaccess文件来删除“index.php”,用2个名称替换param1和param2,并在末尾添加“.html”,因此它们变成:

www.website.com/budget/12345678.html
www.website.com/budget/09876543.html

www.website.com/user/abcdefgh.html
www.website.com/user/qwertzui.html
我得到了这个代码(从网上复制的)。 它删除了.php扩展名,但在内部转发中,它会在URL末尾重写它,忽略参数

有人帮我写代码吗

谢谢:)

您可以尝试:

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

# handle ?param1=...
RewriteCond %{THE_REQUEST} \s/+(?:index\.php)?\?param1=([^\s&]+) [NC]
RewriteRule ^ /budget/%1.html? [R=301,L,NE]

# handle ?param2=...
RewriteCond %{THE_REQUEST} \s/+(?:index\.php)?\?param2=([^\s&]+) [NC]
RewriteRule ^ /user/%1.html? [R=301,L,NE]

## hide .php extension snippet

# To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R=301,NE,L]

RewriteRule ^budget/([^/.]+)/?$ index.php?param1=$1 [L,QSA,NC]

RewriteRule ^user/([^/.]+)/?$ index.php?param2=$1 [L,QSA,NC]

# To internally forward /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*?)/?$ $1.php [L]
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

# handle ?param1=...
RewriteCond %{THE_REQUEST} \s/+(?:index\.php)?\?param1=([^\s&]+) [NC]
RewriteRule ^ /budget/%1.html? [R=301,L,NE]

# handle ?param2=...
RewriteCond %{THE_REQUEST} \s/+(?:index\.php)?\?param2=([^\s&]+) [NC]
RewriteRule ^ /user/%1.html? [R=301,L,NE]

## hide .php extension snippet

# To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R=301,NE,L]

RewriteRule ^budget/([^/.]+)/?$ index.php?param1=$1 [L,QSA,NC]

RewriteRule ^user/([^/.]+)/?$ index.php?param2=$1 [L,QSA,NC]

# To internally forward /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*?)/?$ $1.php [L]