Wildcard Url Pattern using htaccess - php

i am looking for htaccss code. i want like if some one vist
domain.com/folder/ver-234123.html
domain.com/folder/ver-4234234.html
domain.com/folder/ver-kahsdkf.html
so it all baiscally open domain.com/folder/index.php
i will randomize the number/digits after ver- via php.

You want to use mod_rewrite.
Assuming "/folder" actually exists and this .htaccess would be within it.
This should be a fairly simple rewrite. Something like:
RewriteEngine on
RewriteRule ^/?ver-[a-z0-9]*\.html index.php [L,QSA]

Related

Multiple vanity URLs for different php files?

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/

Making php handle get URI's like symfony

I am starting a project that is too small to use a framework for, but I would like to make the uri look like how symfony has them.
e.g.
example.net/directory/var/value/
instead of
example.net/directory?var=value
Thanks for any help.
the keyword you have to look for is: url rewrite
here is a simple example
make a file named .htaccess into your root
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^directory/([^/]+)/([^/]+) /directory.php?var=$1&value=$2 [NC]
and that happens:
http://domain.com/directory/AAA/123 => /directory.php?var=AAA&value=123
more over here: http://corz.org/serv/tricks/htaccess2.php

How to create URLs like www.example.com/EN/login

I want to add multiple languages to my website in the way that I would like something like http://www.example.com/EN/login for English and http://www.example.com/DE/anmelden for German. Both of the URLs should pass the requests to http://www.example.com/login.php.
Now I am wondering in general how would you create a URL like that, do I need a file anmelden.php inside the DE directory? Or does the directory DE/anmelden not exist and its all done with .htaccess? And how can I extract the "DE" and "anmelden"?
Well, since you are using PHP, you will want to use a .htaccess file to do your URL rewriting. Check out this beginner's guide to mod_rewrite.
This is the example they use, which rewrites from index.php?page=software to /page/software:
RewriteEngine on
RewriteRule ^page/([^/\.]+)/?$ index.php?page=$1 [L]
The EN/DE can be achieved through htaccess and passed to a script. You can extract the URL by using $_SERVER['REQUEST_URL']; from that script and output/forward the proper view
http://net.tutsplus.com/tutorials/other/using-htaccess-files-for-pretty-urls/
This will help you allot not in languages but in other functionality too

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