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

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

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]

How to write a php code so that I can create a link like this "http://website/2017/name.html" [duplicate]

This question already has answers here:
Reference: mod_rewrite, URL rewriting and "pretty links" explained
(5 answers)
Closed 5 years ago.
I'm sorry that my question itself is not the way it should be. I am new to php and the links to open a post ( let's take that I am creating a website something like a blog ) is like open.php?id=sth
I have seen in blogger and many other sites the links to open a post is in the type I have given in the question head. I would like to know how this is done. Is this in a way by which they create a directory and make an html file (as in the example) in that particular directory?
You can do that with a ".htaccess" file and apache url rewrite module.You don't need to create a directory.
Create a ".htaccess" file on the root folder and add something like this:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^([^?]*) ./open.php?params=$1 [L]
This will make your url like "http://example.com/2017/name"
You can debug your parameters with that code:
var_dump($_GET);
open.php?url=http://example.com
<?php
header('Location: '+urldecode($_GET['url']);
?>

How I can redirect my site links via an .htaccess file? [duplicate]

This question already has answers here:
Htaccess Remove part of URL
(2 answers)
Closed 8 years ago.
How I can redirect my site links by .htaccess file. From the links now:
domain.com/topic/30635/name-thread-non-english
To
domain.com/30635/name-thread-non-english
So, I want to remove: "topic" and change with each subject: "30635" and "name-thread-non-english".
What to add in the .htaccess file?
You can rewrite a rule to do this, something like:
RewriteRule ^([a-z]+)\/([0-9]+)\/([a-z\-]+)?$ $2/$3 [L,R=301]
Example:
uri: topic/30635/name-thread-non-english
^([a-z]+)\/ == topic/ == $1
([0-9]+)\/ == 30635/ == $2
([a-z\-]+)?$ == name-thread-non-english == $3
the new url: $2/$3 == 30635/name-thread-non-english
Use a rewrite rule as the following
RewriteRule ^topic/(.*)$ http://domain.com/$1 [R=301,NC,L]

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