I have an web application开发者_StackOverflow社区 in PHP with urls like this: https://www.domain.com/?mod=test&act=view
My problem is that when I try to use mod_rewrite to redirect users to new link: https://www.domain.com/view-test
I have the following rule under my .htaccess:
RewriteRule ^\?mod=test&act=view$ /view-test [L,R=301]
If I remove the leading "?" from the above rule the redirection works but obsiouly I get a 404 error. But if I keep it nothing happens
Can anyone help?
You can create a new rule for view-test
:
RewriteEngine On
RewriteRule ^mod=test&act=view$ /view-test [L,R=301]
# new rule for view-test
RewriteRule ^view-test$ /index.php [L]
Update:
This works perfectly for me:
Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^/index\.php$
RewriteCond %{QUERY_STRING} ^mod=test&act=view$
RewriteRule ^(.*)$ /test-view? [L,R=301]
RewriteRule ^test-view/?$ /index.php [L]
Get the values:
<?php
$request = str_replace("/", "", $_SERVER['REQUEST_URI']);
$request = explode("-", $request);
print_r($request);
Output:
Array
(
[0] => test
[1] => view
)
Hope this helps!!
精彩评论