1

I have a simple php and htaccess question.

I have this $_GET :

if(isset($_GET['word'])) {
  if (isset($_GET['id'])) {

  }
}

So the url will be :

example.com/index.php?word=test&id=555

Now, i want to convert the url to :

test.example.com/555/

i have a htaccess code like this :

RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} ^([^.]+) [NC]
RewriteCond %{QUERY_STRING} !(?:^|&)word=[^&]+(?:&|$) [NC]
RewriteRule ^ %{REQUEST_URI}?word=%1 [QSA,L]

But it is just for one variable, not both of them.

How can i do that with htaccess ?

1 Answers1

1

See if this works for you:

RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{QUERY_STRING} ^word=([^&]+)&id=([^&]+)$ [NC]
RewriteRule ^index\.php$ %{REQUEST_SCHEME}://%1.%{HTTP_HOST}/%2/ [R=301,L,QSD]
Laird
  • 148
  • 6