Reputation: 87
I want to make a rewrite,and my script is like this :
<?php
$id = $_GET['id'];
if($id) {
echo "Your id are $id";
} else {
echo "Id are missing";
}
?>
with .htaccess
i want to make it in my url like this : http://example.com/something/id
So,what must i edit
in my php
and add to my .htaccess
?
Upvotes: 1
Views: 2703
Reputation: 41249
Try the following in Root/.htaccess
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ /file.php?id=$1 [NC,L]
Replace /file.php with your file .
This will internally redirect
example.com/123
to
example.com/file.php?id=123
Upvotes: 3
Reputation: 342
you can get the variable values automaticly by this method
RewriteEngine On
RewriteBase /
RewriteEngine On Options All -Indexes RewriteBase /directoryname/ RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
############### SEO ##########################
#
http://www.example.com/hello/booboo/ it takes the url after .com/
RewriteRule ^(.*)$ getme.php?url=$1 [QSA,L]
for example if i enter http://www.example.com/hello/bobo/
it is going to replace and take "/hello/bobo/" part now you can use this in .htacces file Also if you want to redirect to another page and filter the variable value you should modify $1 because all data in this.
edit: in that example i get url after my domain and i redirect to get.php also you can divide the url using split method by "/" Let's see the get.php page to understand this method
getme.php:
<?php
//we redirect to get in url=$1 so our get method name is url
$parca = explode("/", $_GET["url"]); //and we divided by slash the url.
echo $parca[0];//this is first part "/hello/
echo $parca[1];// and this is second part "/booboo/;
?>
Upvotes: 1