I want to remove question mark & .php extension from the url using .htaccess -
i have problem redirect url in .htaccess. want remove .php & question marks url.
for example: www.example.com/test.php?id=12 www.example.com/test/12 need format.
i tried using code in .htaccess
options +followsymlinks -multiviews # turn mod_rewrite on rewriteengine on rewritebase / ## don't touch /forum uris rewriterule ^forums/ - [l,nc] ## hide .php extension snippet # externally redirect /dir/foo.php /dir/foo rewritecond %{the_request} ^[a-z]{3,}\s([^.]+)\.php [nc] rewriterule ^ %1 [r,l] # internally forward /dir/foo /dir/foo.php rewritecond %{request_filename} !-d rewritecond %{request_filename}.php -f rewriterule ^(.*?)/?$ $1.php [l]
this code removes .php extension url. need remove question mark.
that code appears 1 of answers :)
replace code this:
options +followsymlinks -multiviews # turn mod_rewrite on rewriteengine on rewritebase / ## don't touch /forum uris rewriterule ^forums/ - [l,nc] ## hide .php extension snippet # externally redirect /dir/foo.php?id=123 /dir/foo rewritecond %{the_request} ^get\s([^.]+)\.php\?id=([^&\s]+) [nc] rewriterule ^ %1/%2? [r,l] # internally forward /dir/foo/12 /dir/foo.php?id=12 rewritecond %{request_filename} !-d rewritecond %{request_filename}.php -f rewriterule ^(.+?)/([^/]+)/?$ $1.php?id=$2 [l,qsa] # externally redirect /dir/foo.php /dir/foo rewritecond %{the_request} ^get\s([^.]+)\.php\s [nc] rewriterule ^ %1 [r,l] # internally forward /dir/foo /dir/foo.php rewritecond %{request_filename} !-d rewritecond %{request_filename}.php -f rewritecond %{query_string} ^$ rewriterule ^(.*?)/?$ $1.php [l]
Comments
Post a Comment