Rewrite URL to MySQL value [duplicate] - php

This question already has answers here:
How can I create friendly URLs with .htaccess?
(8 answers)
Closed 8 years ago.
I have a PHP script that queries the database with the id specified in the URL:
http://www.example.com/articles.php?id=5
But I want the URL not to have the id in it but the title that's in the same database in another column. So I basically need to have a link that looks like this:
http://www.example.com/articles/title-of-the-fifth-article
and search for this title in the database so I can rewrite the URL in the .htacces file to where it specifies the id.

This should work:
Add this to the .htaccess file
RewriteEngine On
RewriteRule ^articles/(.*) articles.php?title=$1 [L]
and the following to the articles.php file:
<?php
echo $_GET['title'];
?>

Related

.htaccess redirect to php file [duplicate]

This question already has answers here:
Reference: mod_rewrite, URL rewriting and "pretty links" explained
(5 answers)
Closed 2 years ago.
because .htacces including the syntax are totally new territory for me, I currently don't know how to create a specific redirect. I have given the following link:
www.example.com/RANDOM_STRING
This link should redirect via .htaccess to a PHP file where RANDOM_STRING is saved into a GET Parameter. Roughly speaking, it should be redirected something like this:
www.example.com/RANDOM_STRING > www.example.com/router.php?link=RANDOM_STRING
Is it even possible to redirect something like this via htaccess?
Thx
To redirect /router.php/?link=RANDOM_STRING to /router/ you can try something like the following near the top of your .htaccess file (using mod_rewrite):
RewriteEngine On
RewriteCond %{QUERY_STRING} ^link=
RewriteRule ^link/$ /link/? [R,L]

Create better URL - .htaccess [duplicate]

This question already has answers here:
Reference: mod_rewrite, URL rewriting and "pretty links" explained
(5 answers)
Closed 3 years ago.
My URL is looking now like this:
localhost/en/products/bear-toys/bear.php?id=26123
And i need to looks like this:
localhost/en/products/bear-toys/bear/26123
or if i can get title of that product and store into URL:
localhost/en/products/bear-toys/bear/blue-bear.php
I know there is solution with .htaccess but im not good one in .htaccess. So any kind of help will be good. Thanks all
If you want everything after products you can do something like this in htaccess and in PHP. products.php can be the page you want to write to to accept the param(s)
RewriteEngine On
RewriteRule ^(.*)/products/(.*)$ product.php?lang=$1&q=$2 [L,NE]
and this in PHP
$lang = $_GET['lang'];
$params = explode('/', $_GET['q']);
echo $lang . '<br>';
var_dump($params);

I want to rewrite a url in .htaccess file [duplicate]

This question already has answers here:
URL rewriting with PHP
(5 answers)
Closed 4 years ago.
I want to rewrite a url in .htaccess file. in localhost for localhost/pdo/connect?id=3 as localhost/pdo/connect/3 I am using this
RewriteEngine On RewriteRule ^/connect/([0-9]+)$ connect.php?id=$1 [L].
But in connect.php I am getting an error:
undefined index id in $_Get["id"]
Try this one
RewriteCond "%{REQUEST_URI} "!connect.php"
RewriteRule ^connect/([^/]+).*" "connect.php?id=$1" [L,QSA,PT]
above rule working as follow.
www.sitename.com/connect/id

I need to hide .php file name in url [duplicate]

This question already has answers here:
How to make .php extension not appear on website? [duplicate]
(2 answers)
Closed 9 years ago.
I want to hide the file name with the extinction of .php.I tried to write .htaccess file to restrict my URL.but it is not hiding. any one can help me step by step how to hide the URL.
bellow I mentioned actual URL.and expected URL.
Actual URL : varthakindia.com/inners.php?cid1=Hotels
Expected URL: varthakindia.com/Hotels/
In .htaccess
RewriteEngine On
RewriteRule ^Hotels$ inners.php?cid1=Hotels [L,NS]
Use mod_rewrite
RewriteEngine on
RewriteRule ^Hotels/?$ inners.php?cid1=Hotels [L, NS]

How to generate seo friendly URLs use .htaccess with PHP? [duplicate]

This question already has answers here:
Closed 10 years ago.
I use GET in index.php:
$request=isset($_GET['m']) && $_GET['m']!='';
$requestFile=isset($_GET['files']) && $_GET['files']!='';
My link is in the format: localhost:81/Template/index.php?m=index&files=Acc.
How do I use a .htaccess file or PHP to rewrite to: localhost:81/Template/Acc/index.html or php?
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^Template/([^/]+)/([^/.]+)\.html$ /index.php?m=$2&files=$1 [L]
To obtain your page from:
localhost:81/Template/Acc/index.html

Categories