PHP-Mod_用参数重写
我有一个关于mod_rewrite的问题-我有以下URL:PHP-Mod_用参数重写,php,apache,.htaccess,mod-rewrite,Php,Apache,.htaccess,Mod Rewrite,我有一个关于mod_rewrite的问题-我有以下URL: http://website.com/profile/index.php?a=profile&u=username 我正试图将其改写为: http://website.com/profile/user/username 我的.htaccess文件中有以下内容: RewriteEngine on RewriteRule ^/profile/user/([^/]*)$ /profile/index.php&a=profi
http://website.com/profile/index.php?a=profile&u=username
我正试图将其改写为:
http://website.com/profile/user/username
我的.htaccess
文件中有以下内容:
RewriteEngine on
RewriteRule ^/profile/user/([^/]*)$ /profile/index.php&a=profile&u=$1 [L]
虽然当转到重写的URL时,我看不到该页面。我只看到default index.php页面。我尝试通过打印获取参数:print\r($\u-GET)代码>
这给了我以下信息:
Array ( [a] => u [q] => /username)
现在我的问题是-如何将第一个URL重写为第二个URL?显然,a
是空的,u
还包含一个/
模式\u重写
试试这个
RewriteCond %{QUERY_STRING} ^$ [OR]
RewriteCond %{QUERY_STRING} ^query=(.*)$ [NC]
RewriteRule ^/old-search$ /search/%1 [NC,L,R=301]
或
对于url:localhost/profile/user/test
-print\r($\u GET)
返回:
Array ( [a] => profile [u] => test )
您是否可以尝试:RewriteRule^/profile/user/([^/]*)$/index.php&a=$1&u=$2[L]
@测试然后a
参数变为user
-应该是profile
,以便index.php页面获得正确的文件。请参阅上面的编辑@OliverBjA为什么有“&a=profile&u=1美元”?我想你应该有?a=profile&u=1美元。“?”而不是“&”。(在您的htaccess中)。@测试a参数仍然是用户-您将a更改为$1-但用户仍然被声明。您真的认为这将满足OP的要求吗?@Aelmasry“旧搜索”和“博客”有什么用?
RewriteEngine on
RewriteRule ^profile/user/([^/]*)$ index.php?a=profile&u=$1 [L]
Array ( [a] => profile [u] => test )