.htaccess redirect to php file [duplicate] - php

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]

Related

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

How remove .php extension from codeigniter? [duplicate]

This question already has answers here:
CodeIgniter removing index.php from url
(35 answers)
Closed 5 years ago.
My link show this:
http://localhost/project/index.php
I want this:
http://localhost/project/
Do not display extension
You don't understand MVC pattern, there is no direct access to files within URL, everything is redirected to one page.
Full URL: http://localhost/project/home/about
root: http://localhost/project
controller: home
method inside given controller: about
Read more about MVC in Codeigniter's website: https://www.codeigniter.com/user_guide/overview/mvc.html
Or here: https://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller
CodeIgniter provide Routing rules/URI Routing for this.
You can achive this by adding variable to $route array in
/application/config/routes.php file
$old_path = 'home/about'; // no need to add .php to about
$new_path='home/about'; //or about or any other name you want
$route[$new_path] =$old_path;
Now you can visit page by only
http://localhost/project/home/about
For more details :-
https://www.codeigniter.com/user_guide/general/routing.html?highlight=route
Codeigniter's mvc works as project_folder/index.php/controller/function.
If you modify this behaviour with htaccess it might collapse the behaviour of the framework.
Learn how it works and get clarified. This link might help you.
Create a file with the name ".htaccess" just ".htaccess" NOT "test.htaccess" or so.
Write this code in it ->
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
Now you can link your sites like this -> Test

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']);
?>

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