URL rewriting in PHP using htaccess file - php

My URL is
localhost/Interview/php/SEO_URL/01-example/create_user.php
want to change this into
http://localhost/Interview/php/SEO_URL/01-example/CreateUser
want to create a base url like this
localhost/Interview/php/SEO_URL/01-example/
How ?

You can use the following rule in /root/.htaccess :
RewriteEngine on
RewriteRule ^interview/php/SEO_URI/01-example/create_user/?$ /Interview/php/SEO_URL/01-example/create_user.php [NC,L]
This will internally redirect the requestd url :
interview/php/SEO_URI/01-example/create_user
to
/Interview/php/SEO_URL/01-example/create_user.php

Related

Read parameter using rewriting engine

I have this type of url :
domain.com/articles/title
And i want to rewrite this url in :
domaic.com/articles.php?id=title
I use this rewrite condition:
RewriteEngine On
RewriteRule ^articles/(.*)$ articles.php?id=$1 [QSA,L]
I can show the page articles.php but i try to read value of id's variable with $_GET['id'] but is empty.
Thank in advance for your reply

How to create htaccess with redirect html and get parameter from last of url

I have url :
http://localhost/panel/dev/dashboard
how to create htaccess, i want to :
http://localhost/panel/home.php?i=dashboard
Something like this should work:
RedirectRule ^/panel/dev/(.+)$ /panel/home.php?i=$1 [L,QSA]

htaccess rewrite url rule trouble detect $_GET isset

RewriteEngine On
RewriteRule ^about/([^/.]+)/?$ about.php?id=$1 [L,QSA]
I have a page use htaccess rewrite rule for url
/about/33
the page require $_GET['id'] to fetch db
however i have trouble to detect GET variable isset
if(isset($_GET['id'])){fetch data...}else{header("location:...");}
if user only enter /about/ without $GET['id'] the page will not found instead run header("location");
is anyway to solve this?
try this:
RewriteRule ^about/([^/.]*)/?$ about.php?id=$1 [L,QSA]
Put * instead of +

Get Page Number from Rewrited URL

i wrote this Rewrite Rule :
RewriteRule ^(products)/(page[0-9]+)?/?$ index.php?action=$1&page=$2 [L]
in following url this will happen :
rewrited url : http://www.silvergroup.ir/products/page2
what actually is : http://www.silvergroup.ir/index.php?action=products&page=page2
but i need the number of page only and whole of page variable is optional, this means following url is allowed :
http://www.silvergroup.ir/products
thank you
Use this rule instead:
RewriteRule ^(products)(?:/page([0-9]+))?/?$ index.php?action=$1&page=$2 [L,NC,QSA]
This will forward
/products to /index.php?action=$1&page=
/products/ to /index.php?action=$1&page=
/products/page2 to /index.php?action=$1&page=2

url php multi method get using .htaccess

if i have a url like:
domain.com/profile.php?id=1&lang=en
Can i get a url like this using htaccess?
domain.com/1/en
thanks
This is how i would do it in .htaccess
RewriteEngine On
RewriteRule ^/1/en$ /profile.php?id=1&lang=en

Categories