Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

129
Views
htaccess rewrite fake directories to GET parameters in PHP

My htaccess file is

RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]

RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f

RewriteRule ^news/(.*)$ index.php?news=$1 [QSA]

so if I goto https://example.com/news/2022-04-01 it should really goto https://example.com?news=2022-04-01 and according to htaccess.madewithlove.com that it what it evaluates to. However, the PHP (index.php in this case), still sees it as /news/2022-04-01 and the $_GET array is empty. Am I missing something really obvious since the whole point of the rewrite is to change it to a GET parameter before it hits my PHP file. Putting this at the start of my PHP file

<?php
echo "https://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]<br/>";
print_r($_GET);
die();

shows array() if I pass it as a directory (which shows it does just goto index.php) but array('news'=>'2022-04-01') if I do it as 'normal' parameter passing. So, can it be done in PHP (or JQuery/Javascript).. And if it can be done, please don't hardcode 'news', there are 8 different possibilities being passed so I need a generic routine. Many thanks Adrian

about 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!