0

How do I point a URL to a file so when I go to the URL it points to that file but doesn't change the URL. For example: mydomain.com/orders/create should point to /myfiles/orders-create.php

then when I go to mydomain.com/orders/create it will display all the contents of orders-create.php.

Any ideas?

  • Does this answer your question? [URL rewriting with PHP](https://stackoverflow.com/questions/16388959/url-rewriting-with-php) – jrswgtr Sep 01 '20 at 20:29
  • Yes that showed the HTML content but none of the styling that is on a PHP include. Showing a 404 error for all the css and image files. –  Sep 01 '20 at 20:32

2 Answers2

0

If you want to do it on the server-side you could edit the .htaccess file similar to this question's answer.

The main changes you're looking at are:

RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule (.*)$ $1.php [NC]

This would let you create files without an extension and it would run force run the PHP interpreter.

Here's a good read for pretty URLs to find out more ways you could do this, and it'll explain more about what they actually are.

Zinapse
  • 28
  • 7
0

If you can change create-order.php, then you can make it so that it does not rely on relative paths. One way to do this is to create a bootstrap.php file that has all of the includes and then your "leaf" PHP files only have to find this bootstrap.php file.

Another option is to set the PHP path. If you change the include path to include the root of the directory, then when including files in create-order.php will look in the root and it will find them. You can set the include path in your PHP files or in the PHP configuration.

If you don't want or can't change create-order.php then one way to do this would be via the webserver. For example, in apache, you can use mod_rewrite to do just that, have a public URL actually invoke a specific local file. The rewrite configuration might look like this (example for just this one file):

RewriteEngine on
Options +FollowSymlinks

RewriteRule ^orders/create to create-order.php$ create-order.php [L]

or a catch-all rule with this (untested):

RewriteRule ^orders/(.*)$   $1?%{QUERY_STRING} [L]
alanboy
  • 369
  • 3
  • 15