url php multi method get using .htaccess - php

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

Related

URL rewriting in PHP using htaccess file

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

Can't get $_GET variables from mod_rewritten URL

I'm trying to rewrite a URL in PHP from example.com/homehub/whatweneed.php?sort=default to example.com/homehub/whatweneed/sort/default.
I've got the following code in my .htaccess file:
RewriteEngine On
RewriteRule ^sort/([A-Za-z0-9]+)/?$ ^whatweneed.php?sort=$1 [QSA,PT,L]
It's rewriting the URL to what I want but I can't seem to get any of the variables passed through via $_GET.
Try
$_SERVER['REQUEST_URI']
or
$_SERVER['REDIRECT_URL']

how to Change a GET method URL to clean URL in php?

This is an URL that created by GET method in php to send DATA parameter to archives.html page:
http://127.0.0.1/archives.html?option=com_archive&date=16-2-2014
Is there any way to clean this URL?
I want to do something like this (and I can send parameter too!)
http://127.0.0.1/archives.html/16-2-2014
Can I do that by mod_rewrite?
(I am developing a component on joomla3)
You can use this rule in your root .htaccess:
RewriteEngine On
RewriteRule ^(archives\.html)/([0-9-]+)/?$ /$1/?option=com_archive&date=$2 [L,NC,QSA]
RewriteEngine On
RewriteRule ^([^/]*)$ /archives.html?option=com_archive&date=$1 [L]
This htaccess would do this job for you
by url i assume this is joomla
this doc might help you
http://docs.joomla.org/Enabling_Search_Engine_Friendly_(SEF)_URLs_on_Apache
One way to do this in PHP:
$original_url = 'http://127.0.0.1/archives.html?option=com_archive&date=16-2-2014';
$new_url = explode('?', $original_url);
$clean_url = $new_url[0];

change php page url using htaccess

I want to change the url from
http://mywebsite/address.php?state=oh&office_id=1425
to
http://mywebsite/office/{variable inside my php page}.php
appreciate if you can help me
This should work:
RewriteEngine On
RewriteRule ^office/([0-9]+).php$ address.php?state=oh&office_id=$1
Which would result in:
http://expample.com/office/1425.php
Or if you'd like the state to be dynamic as well, you could do this:
RewriteEngine On
RewriteRule ^office/([a-zA-Z]+)/([0-9]+).php$ address.php?state=$1&office_id=$2
Which would result in:
http://expample.com/office/oh/1425.php
I would suggest to have a look at mod_rewrite Apache module.
You can do various URL manipulations with it.
http://httpd.apache.org/docs/current/mod/mod_rewrite.html
Beginner's guide:
http://www.workingwith.me.uk/articles/scripting/mod_rewrite

how can I rewrite URL to fancy url?

when my user logs in, I want the get variables that were sent rewrote onto the URL like so:
http://mysite.com/mygetvar1/mygetvar_value1/mygetvar2/mygetvar_value2/
or
mysite.com/mygetvar1=mygetvar_value1/mygetvar2=mygetvar_value2/
How can I do this?
Please help! Thanks!
Codeigniter can offer you like that. Many other PHP frameworks offer that as well.
Try this.
RewriteRule /([^/]*)/([^/]*)/([^/]*)/([^/]*)/ /login.php?$1=$2&$3=$4 [R=301]
RewriteRule /([^/]*)=([^/]*)/([^/]*)=([^/]*)/ /login.php?$1=$2&$3=$4 [R=301]
First you need the mod_rewrite module enable.
After, put this in your config file :
RewriteEngine on
RewriteRule ^ads/(rims|tires|combo)/([0-9]+)/(.+).html /ad.php?noAds=$2 [L,QSA]
This is a example.
Your url will look like : http://www.yourwebsite.com/ads/rims/331/title.html
but you will call the url : http//www.yourwebsite.com/ad.php?noAds=331
For your regex , you should use a site like http://www.rubular.com
You can use the .htaccess file or put in directly in the httpd.conf file

Categories