How does one make a view contain without using the get variable in PHP
I am trying to display post/id like this
www.domain.com/view/1234
instead of
www.domain.com/view.php?id=1234
How does one make a view contain without using the get variable in PHP
I am trying to display post/id like this
www.domain.com/view/1234
instead of
www.domain.com/view.php?id=1234
Assuming you have an Apache server with the mod_rewrite
module enabled, you can create a new .htaccess
file with the following content:
// First of all we want to set the FollowSymlinks option,
// and turn the RewriteEngine on
Options +FollowSymlinks
RewriteEngine on
// This is the rule that changes the URL
RewriteRule ^view/([^/.]+)/?$ view.php?id=$1 [L]
This would do exactly like you wanted and redirects any /view/123
to view.php?id=123
.
If what you're looking for is the ability to parse the uri, you can use this:
$uri = $_SERVER["REQUEST_URI"]
$parts = explode("/",$uri)
The last element in your $parts array should be your view id.
Drupal(1) contains the following function to do exactly this:
function arg($index) {
static $arguments, $q;
if (empty($arguments) || $q != $_GET['q']) {
$arguments = explode('/', $_GET['q']);
$q = $_GET['q'];
}
if (isset($arguments[$index])) {
return $arguments[$index];
}
}
(1) I do not advocate using Drupal, I merely use it as an example.
This is done via webserver url rewriting.
Here's some references for Apache (using mod_rewrite
):
You need to rewrite the URL with htaccess and intercept it somehow using PHP and loading the file from somewhere.
Is it what are you looking for?