0

I'm trying to do pretty urls but seems that they wont work for some reason. What I'm trying is to redirect this two URLs

https://www.example.com/page.php?page=newpage
https://www.example.com/page.php?page=newpage&countryId=1

to

https://www.example.com/newpage/
https://www.example.com/France/newpage/   <--- France is with countryID=1 in db.

What I have tried in .htaccess is

RewriteEngine on
RewriteCond %{QUERY_STRING} ^page\=newpage&countryId\=$
RewriteRule ^page\.php$ https://www.example.com/France/newpage/? [R=301,L]

RewriteCond %{QUERY_STRING} ^page\=newpage$
RewriteRule ^page\.php$ https://www.example.com/newpage/? [R=301,L]

What I get is blank pages for both.

S.I.
  • 3,250
  • 12
  • 48
  • 77
  • Your 2nd rule matches your first URL, but in the 1st rule you've omitted the `1` in `countryId=1`. Otherwise, these URLs should redirect as required. Is it redirecting? Is your site configured to manage requests for the target URL? (_Aside:_ You don't need to backslash-escape the literal `=` in the regex.) – MrWhite May 16 '22 at 10:35
  • @MrWhite, the URL which has `countryID` doesn't redirect. The other one is redirecting but the page is blank/white. – S.I. May 16 '22 at 10:43
  • Like I say, you are missing the `1` - so it won't redirect the URL in question. "The other one is redirecting but the page is blank/white." - so does it display the page if you request the target URL directly?! – MrWhite May 16 '22 at 10:44
  • Nope, no matter how I load the page is still blank. No errors or anything. – S.I. May 16 '22 at 10:52
  • So, your problem isn't the "redirect" (which is what your question is about), but the target URL `https://www.example.com/newpage/` doesn't actually work???? What are you trying to do exactly? Implement some "pretty" URLs? – MrWhite May 16 '22 at 10:54
  • Yes, pretty urls. Without adding this to the htaccess the page loads normally and showing everything. You're right and I've changed the title of the question – S.I. May 16 '22 at 10:54

0 Answers0