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.
Related
I'm very new to htaccess and mod_rewrite things, so please forgive me the possibly stupid question :-)
I have a Links like that on my menu
teams/senioren/herren-1
teams/senioren/damen-1
etc.
and I want to redirect it to
team.php?team=herren-1
team.php?team=damen-1
My htaccess looks like that:
RewriteEngine On
RewriteRule ^teams/([^/]*)/([^/]*)$ team.php?team=$2 [L,QSA]
That works on localhost when I click the link one time. The URL then gets https://localhost/teams/senioren/herren-1. But when I click a second time I get https://localhost/teams/senioren/teams/senioren/herren-1. So it looks like it appends the new URL to the old one.
Can anyone help me?
Thank you
Solution: Use absoluth Path like arkascha mentioned in the comments.
So in my case use /teams/senioren/herren-1 instead of teams/senioren/herren-1
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.
So I heard you can use htaccess to rewrite the website url. For example I have a php page to view threads/posts which looks like this:
http://website.com/view.php?id=133
I have been told I could make it look like
http://website.com/view/133
I also have this link
http://website.com/delete.php?id=144
and I want it to look like this
http://website.com/delete/144
How would I go about doing this?
Thanks.
RewriteRule ([a-z])/([0-9])\ $1.php?id=$2
([a-z]) will replace your page name ([0-9]) will replace your id respectively in right hand side
Please refer
http://corz.org/serv/tricks/htaccess2.php
Yes, you can do all that using .htaccess.
Check out my answer Redirecting localhost/xxx to localhost/xxx.php in WAMP
I hope it helps.
RewriteRule ^(.*)/([0-9]+)$ $1.php?id=$2 [NC,L]
You have to give the url as http://website.com/delete/144, then it will be redirected to delete.php with 144 as id.
For example,
Delete
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.
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