1

Default url view looks like this: https://example.com/user.php?page=history
I change it with .htaccess to: https://example.com/user/history/
Problem in navigation bar which I made with radio type form. And it gives me: https://example.com/user/history/?page=history
How to change it? Help pls.

.htaccess

RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^user/(\w+)$ /user.php?p=$1
RewriteRule ^user/(\w+)/$ /user.php?p=$1
<form name='page' id='page'>
     <input id="history" type="radio" name="page" <?php if ($p == 'history') { ?>checked='checked' <?php } ?> onChange="autoSubmit();" value="history" >
     <label for="history">Історія замовлень</label>

     <input id="settings" type="radio" name="page" <?php if ($p == 'settings') { ?>checked='checked' <?php } ?>onChange="autoSubmit();" value="settings">
     <label for="settings">Налаштування</label>
</form>
<script>
  function autoSubmit(){
    var formObject=document.forms['page'];
    formObject.submit();}
</script>
<?php
$p="";
if(isset($_GET["page"])){
    $p=$_GET["page"];
}
?>

Radio type menu needs to be like this:

1 Answer 1

1

EDIT: Please try following rules as per shown samples in comments.

RewriteEngine ON
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(?:[^/]*)/([^/]*)/?$ user.php?page=$1 [L]


With your shown attempts, please try following htaccess Rules file, make sure your php file(s) and htaccess are in same folder. Please make sure to clear your browser cache before testing your URLs.

RewriteEngine ON
##Doing external rewrite to friendly url here.
RewriteCond %{THE_REQUEST} \s/(.*)/?\?page=([\w-]+)\s [NC]
RewriteRule ^ /%1/%2 [QSD,R=301,L,NE]
##Doing internal rewrite to php files here.
RewriteRule ^(?:[^/]*)/([^/]*)/?$ user.php?page=$1 [QSA,L]
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.