简体   繁体   English

.htaccess重写多个页面的URL,并获取传递给该URL的参数

[英].htaccess rewrite URL for multiple pages and fetch arguments passed to the URL

I have the following .htaccess code which works as expected which is 我有以下.htaccess代码可以正常工作

 http://example.com/profile.php

to

 http://example.com/someprofile

But I'm passing arguments in the URL such as, 但是我在URL中传递了参数,例如,

 http://example.com/profile.php?username=someprofile

I need the above to be changed to the following, 我需要将以上内容更改为以下内容,

 http://example.com/someprofile

I also need to fetch the argument 'someprofile' in PHP using $_GET['username']. 我还需要使用$ _GET ['username']在PHP中获取参数'someprofile'。 I'm exhausted of chances.. 我很累的机会..

This should work for you: 这应该为您工作:

RewriteEngine On
RewriteCond %{THE_REQUEST} ^(GET|POST)\ /profile\.php\?username=(.*)\ HTTP
RewriteRule ^ /%2\? [R=302,L]

RewriteRule ^(.*)$ profile.php?username=$1 [L]
http://example.com/profile.php?username=([a-z]*) 

then you can redirect to 然后您可以重定向到

http://example.com/$1 

I'm not sure if it is $1 or \\1 but you have to use regular expression 我不确定是$ 1还是\\ 1,但是您必须使用正则表达式

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

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