I have a URL that will be something like example.com/index.php?p=test so that the PHP will load the test variable using $_GET['p']. The URL can already be simplified to example.com?p=test; however, I wish to simplify this in my .htaccess to site.com/test. How would i go about doing this?
Add a comment
|
1 Answer
Place the following in your .htaccess file:
RewriteEngine on
# The two lines below allow access to existing files on your server, bypassing
# the rewrite
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) index.php?p=$1 [QSA]
You can then access whatever from example.com/whatever like the following:
$value = $_GET['p']; // "whatever"
8 Comments
hetoan2
I have other files on my server though, using this doesn't allow me to access any of them. For instance, i have site.com/forum, which this breaks :( any way I could possibly have it work ONLY on the root, and only if the directory doesn't already exist?
hetoan2
thanks that fixed my directory issue, but I can't seem to access the files from example.com/whatever when i enter it. only when i enter example.com/index.php?p=whatever will it rewrite the url as example.com/whatever
hetoan2
would you mind telling me how to turn
example.com/test into example.com/?p=test; given that example.com/test is not already a directory on the server? |