By jakewashere
I have this snip of .htaccess:
RewriteCond %{REQUEST_FILENAME} index\.php
RewriteCond %{QUERY_STRING} ^id=([0-9]+)$
RewriteCond %{DOCUMENT_ROOT}/u_pages/%1.php -f
RewriteRule .* u_pages/%1.php? [L]
Using an online converter I get this:
location / {
if ($request_filename ~ index\.php){
rewrite ^(.*)$ /u_pages/%1.php? break;
}
}
-Doesn’t work.
What I’m trying to do:
I have a bunch of plain .php documents in /u_pages – e.g. 123.php
I need these to have URLs like this:
example.com/index.php?id=123
The document NAME corresponds with the number after id=
Any help is greatly appreciated, thank you.
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Hi @ ,
You can try the following redirect:
location ^~ /u_pages {
return 301 /index.php%1.php;
}
Not really sure but it should work.
Or with rewrite, the query string is automatically appended unless a ? is added:
rewrite ^/u_pages/$ /index.php$1 permanent;
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
From GPU-powered inference and Kubernetes to managed databases and storage, get everything you need to build, scale, and deploy intelligent applications.