1

For some reason I cant access the query value only for the internal rewrite in .htaccess?

Options +FollowSymLinks

RewriteEngine ON
RewriteBase /

##external redirect
RewriteCond %{QUERY_STRING} ^id=([0-9]*)$
RewriteRule ^(.*)$ /test/user-profile/%1? [R=301,L]

#internal rewrite
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/(.*)/(.*)$ /test/user-profile.php?id=$3 [L]

Here is the entire htaccess file. Its redirecting the url perfectly, just cant get the id value by itself? Thank you

2
  • What URLs are you requesting? And what is the expected URL target? Commented Jan 1, 2022 at 23:39
  • requesting www.example.com/test/user-profile?id=1 then I want the url to be shown to user as www.example.com/test/user-profile/1 and then still have ability to pull the id value through PHP Commented Jan 3, 2022 at 17:36

1 Answer 1

1

This is because you use id= in your rewrite, and you are redirecting the 2nd (/test/user-profile.php?id=N) to the first (/test/user-profile/N)

Change the first:

##external redirect
RewriteCond %{REQUEST_URI} !^/test/user-profile\.php
RewriteCond %{QUERY_STRING} ^id=([0-9]*)$
RewriteRule ^ /test/user-profile/%1? [R=301,L]
Sign up to request clarification or add additional context in comments.

5 Comments

So this does grab the query variable, but now it wont redirect the URL to /test/user-profile/3
That don't change correct rewrite, only with user-profile.php
So im attempting to rewrite www.example.com/test/user-profile?id=3 into www.example.com/test/user-profile/3 with the also the ability to use GET['id']. Are you able to help? thank you for your time
RewriteRule ^(.*)$ /test/user-profile.php?id=$1 [L] keeps saying the query is id=test/user-profile/7
@BlakePrice Where did you get that rule from? It's not mentioned in the question, or the above answer?

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.