this is the real url:
http://web/app/index.php?id=1
here i have used current .htaccess and working fine with me.
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
RewriteRule ^([a-zA-Z0-9_-]+)$ index.php?id=$1
now the url is : http://web.com/app/index/i
and working fine
but here is the problem the real url
http://web.com/app/index.php?id=1&name=abc
how can i set mention url with .htaccess for keep it short or any other good solution for hiding URL-. is it posible to show user only one url like , http://web.com/app but it could go to other pages while the url stay one url static.
regards
If we say, good practice is to rewrite everything to one index
page, like this:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
then in your index.php
you get uri by $uri = $_SERVER['REQUEST_URI']
:
http://example.com/app -> $uri = /app
http://example.com/app/sub-app -> $uri = /app/sub-app
but also query string applies to the $uri
variable:
http://example.com/app/?a=1&b=3 -> $uri = /app/?a=1&b=3
in this case, if you want to examine just uri part before ?
question mark:
$realRri = strtok($uri,'?'); // and you have '/app/' instead of '/app/?a=1&b=3'
next you can examine and manipulate $uri
;
Example:
$trimmedUri = trim($realRri, '/');
if ($trimmedUri == 'app')
{
// you can show app page
}
elseif ($trimmedUri == 'contact')
{
// show contact
}
else
{
// show 404 page not found
}
// you can have some dynamic also also
if (is_file($filePath = 'custom-page/'.$trimmedUri))
{
include $filePath;
}
else
{
// 404 page
}
Final Code (regarding your current script)
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
#rewrite php file
RewriteRule ^([a-zA-Z]+)$ $1.php
#rwwrite with id
RewriteRule ^([a-zA-Z]+)/([0-9]+)/?$ $1.php?id=$2
#rewrite with id and name
RewriteRule ^([a-zA-Z]+)/([0-9]+)/([0-9a-zA-Z]+)/?$ $1.php?id=$2&name=$3
I think what you're looking for is something like AJAX, mostly because of
but it could go to other pages while the url stay one url static.
in which case, you would looking at Javascript and not php. You would need a way to quickly deal with the data and change it how you want it. I've recently started learning Angular, and it shows a lot of promise. Go through the tutorial yourself (just google angular.js and the tutorial is on their website), or some other javascript library (unless you want to hard-code everything, in which case, good luck) like jQuery or MooTools (names mentioned because they're libraries i have knowledge with). To my knowledge (I am no code guru) but a website's URI is what tells the server what to show you. You can make shortcuts
If, however, you want for it to just not have the .php filename, then I believe that
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)\.php\??(.*)$ $1.php&$2
Should, theoretically get you what you want.
Note: I can't test it right now, so it may error out.
EDIT: It does error out, but unfortunately I have to go to sleep. I'll try to get to it tomorr.w