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
Related
I need to set username for my website..
like i have a profile id of user say localhost/ajax/profile.php?id=27
I need to change it like localhost/ajax/xyz
How to achieve it? Please give me valuable link or show me the right way to go or help me out.
i am totally newbie in this town so please help me from 0.
i mean can i have to make php file before applying .htcaccess ? if yes then what to write on that php file?
suppose a person choose a username "abc" so how can the script identify that localhost/ajax/profile.php?id=111 is "abc" and we need to rewrite localhost/ajax/abc
In summary : how to make username like Facebook.
Use .htaccess to hide your file name.php extension
RewriteOptions inherit
RewriteEngine On # enables url rewriting
RewriteCond %{REQUEST_FILENAME} !-d # if requested uri is not directory (!-d)
RewriteCond %{REQUEST_FILENAME}\.php -f # and if there is a file named URI+'.php' (-f)
RewriteRule ^(.*)$ $1.php # then if there is any thing in uri then rewrite it as uri+'.php'
You need to use .htaccess to re-structure your links. You need to create.htaccess if its already not there inside your main folder. You can try this out:
RewriteRule localhost/ajax/(.*) localhost/ajax/profile.php?id=$1 [PT,L,B]
Remember that on RewriteRule, you can't use any php scripts. So, You can't rewrite localhost/ajax/profile.php?id=27 to localhost/ajax/xyz readily. You need to pass localhost/ajax/profile.php?id=xyz and above rule will work fine.
Learn more about .htaccess RewriteRule from here.
u can do it with .htaccess url rewrite method.
it will convert ur url localhost/ajax/profile.php?id=111 to localhost/ajax/111
after then u can also modify to localhost/ajax/myusername
try given link and enjoy 100% satisfied answer
http://www.9lessons.info/2009/11/pretty-urls-with-htaccess-file.html
here u will find some extra tools for ur social network
I am trying to build a site which has the following pages which needs vanity urls,
account.php
questions.php
profile.php
I need to display
www.mysite.com/account?req=settings
www.mysite.com/account?req=questions
www.mysite.com/account?req=answers
as following
www.mysite.com/account/settings
www.mysite.com/account/questions
www.mysite.com/account/answers
And for the other files I need the following,
etc:-
www.mysite.com/questions?id=0484684
As
www.mysite.com/questions/0484684
And
www.mysite.com/profile?id=123456
as
www.mysite.com/profile/123456
Would anyone help me because I really need to make this possible.
I would like to remove the .php extention from the url too.
I like to say that I have no experience in htaccess files.
Thanks for the help, it worked !!!
In your .htaccess file, add these rules:
RewriteEngine on
RewriteBase /
RewriteRule ^account/([^/\.]+)/?$ account.php?req=$1 [L,NC,QSA]
RewriteRule ^questions/([^/\.]+)/?$ questions.php?id=$1 [L,NC,QSA]
RewriteRule ^profile/([^/\.]+)/?$ profile.php?id=$1 [L,NC,QSA]
You should be able to add new rules based on how these work if you need them in the future.
You'll want to use a .htaccess file combined with PHP for complex manipulations like that, I wrote an article on re-writing URLs after asking a similar question on SO:
http://tomsbigbox.com/elegant-url-rewriting/
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
I need help with modifying the url of a website I am working on.
The url is:
domainname.com/view-post.php?title=post-title&pid=2
I can only get it to say
domainname.com/2.html
but need it to say
domainname.com/posts/post-title
Any help will be greatly appreciated.
I would suggest you to use something like:
RewriteRule ^posts/(a-zA-Z0-9\-\.]+)/([0-9]+)/?$ view-post.php?title=$1&pid=$2 [NC,L,QSA]
or
RewriteRule ^posts/([a-zA-Z0-9\-\.]+)/?$ view-post.php?title=$1 [NC,L,QSA]
I found a tool called "URL Re writer Tool" which you can use to generate htaccess code: try it out here : http://www.webconfs.com/url-rewriting-tool.php It's perfect for those who want to Re Write the URLs on their server but don't know what to put in htaccess.
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.