1

I need using this .htaccess file. It only changes the URL from www.mydomain.com/users/user?usernam=myname123&profile=myprofile123&data=mydata123 to www.example.com/users/myname123/myprofile123/mydata123 .

i use

RewriteEngine On
RewriteRule ^user\.php$ - [L]
RewriteRule ^([0-9a-zA-Z\-_.]*)/?$ /users/user.php?username=$1&profile=$2&data=$3[L,QSA]

htaccess in users folder

not work

2
  • complete, path /users/.htaccess , i have another htaccess in home path Commented Nov 13, 2020 at 18:56
  • 3
    As per this meta post and this meta post this question is not at all off-topic for SO so close vote is wrong. This has been discussed again and again and it has been settled already that most of the rewrite rules are created and maintained by developers of the web applications/frameworks. Commented Nov 13, 2020 at 21:14

1 Answer 1

2

With your shown samples, could you please try following rules. This will take anything in REQUEST_URI starting.

RewriteEngine ON
RewriteCond %{QUERY_STRING} ^$
RewriteCond %{THE_REQUEST} /([^/]*)/([^/]*)/([^/]*)/([^/]*)/?\s 
RewriteRule ^(.*) /%1?username=%2&profile=%3&data=%4 [NE,L,NC]

OR(either use above or following one) in case you want to match users in URI then run rules then try following.

RewriteEngine ON
RewriteCond %{QUERY_STRING} ^$
RewriteCond %{THE_REQUEST} /users/([^/]*)/([^/]*)/([^/]*)/?\s 
RewriteRule ^(.*) /users?username=%1&profile=%2&data=%3 [NE,L,NC]

Explanation: Adding detailed explanation for above.

  • RewriteEngine ON: Enabling RewriteEngine here to enable mod rule writing.
  • RewriteCond %{QUERY_STRING} ^$: Checking condition if query string is NULL then go further in rules.
  • RewriteCond %{THE_REQUEST} /users/([^/]*)/([^/]*)/([^/]*)/?\s: Matching regex in THE_REQUEST from /users to till spaces and capturing 3 groups values into back references to be used later.
  • RewriteRule ^(.*) /users?username=%1&profile=%2&data=%3 [NE,L,NC]: Using url rewrite to change URI to as per OP's request which has back references values in it.
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.