How to make HTACCESS URL with getting other variabel PHP - php

I get problem while implement .htaccess file,
for general htaccess like : sitename.com/id/other_var its working very well to getting $_GET Request,
RewriteRule ^sitename.com/id/other_var$ index.php?id=$1&othervar=$2 [L]
my problem is, I need to implement like : sitename.com/id/other?a=x&b=y ,
how it work on htaccess ?
thank you for helping!

Mod Rewrite can use simple regex statements to achieve this..
RewriteRule ^sitename.com/([0-9]+)/(.*)$ index.php?id=$1&othervar=$2 [L]
The above would pass an integer value for id and allow anything passed for othervar

Related

How do i convert my URL's like www.example.com/profile.php?id=xyz into www.example.com/xyz?

I have got different pages in my website(portal) which may take one or more parameters from the URL.
So the URL www.example.com/xyz has to be solved into or like www.example.com/profile.php?id=xyz and the value id should be able to get using GET method.
I'm working on PHP. Any answers would be highly appreciated. (I'm new to PHP and have only basic+ knowledge in it. Please explain briefly.)
To go from: www.example.com/profile.php?id=xyz into www.example.com/xyz you can use the following rule in your .htaccess file:
RewriteEngine On
RewriteRule ^([^/]*)$ /profile.php?id=$1 [L]
Just make sure you clear your cache before testing this.

Neep help rewriting php query string to slashes in the URL

I would like to simplify the url on my website forum,
how can i rewrite this
forum.php?topic=10
to this
forum.php/topic/10
Sure you mean forum.php?topic=10 to forum.php/topic/10? I assume you mean the other way
What you need (untestet):
RewriteRule ^/(.*).php/(.*)/([0-9]+)$ $1.php?$2=$3
But it would be better to make it this way:
RewriteRule ^/(.*)/(.*)/([0-9]+)$ $1.php?$2=$3
Then your Url is only forum/topic/10 without .php
Please take a further look into this:
http://www.addedbytes.com/articles/for-beginners/url-rewriting-for-beginners/

php htaccess url rewrite issue

Im trying to get a url rewrite to work and Im not getting any where. basically I want to have three pages one for music and then general products and the other for mvies, each will have a query string of &pagetype=general etc but the url would be http://shopnbuy.vacau.com/browse/computers.html?pageType=general which will redirect to general_products.php and then there would music_products and also movie_products. So they all have the same url except there is a different parameter &pageType=. Below is my htaccess file this is my first attempt at doing this
# Do not remove this line, otherwise mod_rewrite rules will stop working
RewriteBase /
RewriteEngine On
RewriteRule ^browse/([a-zA-Z0-9_-])\.html general_products.php?department=$1&pageType=general
RewriteRule ^browse/([a-zA-Z0-9_-])\.html music_products.php?department=$1&pageType=music
RewriteRule ^browse/([a-zA-Z0-9_-])\.html movie_products.php?department=$1&pageType=movie
url suppose to look like this
http://shopnbuy.vacau.com/browse/computers.html
All Im getting is an error for each url rewrite
I don't know much htacess, but I used it lately and I found out that you can't actually use "/" effectively. I suggest you change it for "_".
As far as I understand, it may be due the "/" works as the one indicating each argument (I mean A / B sorta logic)
Not sure if I explain myself correctly, hoping someone knowledgeable corrects me since I'm eager to learn about it as well.
RewriteRule ^browse_computers / general_products.php?department=$1&pageType=general ([a-zA-Z0-9_-])
RewriteRule ^browse_music / music_products.php?department=$1&pageType=music ([a-zA-Z0-9_-])
RewriteRule ^browse_movies / movie_products.php?department=$1&pageType=movie ([a-zA-Z0-9_-])
The result, however, will be this:
http://shopnbuy.vacau.com/browse_computers
Bit unsure of your initial url but try this
^browse_(.+)/(.+)$ browse/computers.html?pageType=$1

Custom URL with PHP

I have a small question to ask. Is it possible, via php or htaccess, to change a url like: miodominio.com/users.php?idu=x into something like miodominio.com/username ?
I want it to be Facebook style...Where "username" is the username chosen by idu = x.
There are multiple ways to solve this problem, but here's one that always suits my needs.
Guide all your URL requests through the index.php first and resolve the request in your PHP code second.
1) Use an .htaccess file to direct all URL's through index.php. You'll find one way here by the CodeIgniter framework and a more advanced explanation here. I recommend the CodeIgniter .htaccess guide first if you're inexperienced with .htaccess.
2) Second, use the $_SERVER variable in PHP to extract the URL. Probably with the help of the $_SERVER['REQUEST_URI'], you'll find '/username/' which you can then use to extract the user's data and serve it to them.
Good luck and beware of URL injections using this method.
You need to use apache's mod_rewrite for this. It can translate miodominio.com/username to miodominio.com/users.php?idu=x. There are some good guides about this which are easy to find with Google.
You can try to use this mod_rewrite pattern (add it to the .htaccess):
RewriteEngine On
RewriteRule ^([a-zA-Z0-9_-]+)$ users.php?idu=$1
RewriteRule ^([a-zA-Z0-9_-]+)/$ users.php?idu=$1
you have to write a clean URL in your .htaccess file like :
RewriteEngine On
RewriteRule ^([a-zA-Z0-9]+)/$ users.php?idu=$1
Put the following in your .htaccess
RewriteEngine on
RewriteRule ^([a-z0-9_-]+)/?$ /users.php?idu=$1 [NC]
The [NC] will make it case-insensitive, if you accept only lowercase username, remove the [NC] from the last.

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