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
Related
First, I know how to rewrite a URL like example.com/test.php?id=1.
What I dont know is how to remove the test.php part of the url so that the new url is called:
example.com/1/
I hope someone know how to do that, and yes, I've read a hundreds of SO items about it.
Thanks
I'm not sure what you mean by removing if you are about to rewrite old one into new one.
For example you can do it this way:
RewriteEngine On
RewriteRule tag/s/(.*) test.php?id=$1 [L]
Welcome on Stack Overflow.
I have php wesite using following url,
http://example.com/subfolder/category
Now, i want to remove "subfolder" from url using php, but there can be multiple categories which can come and i dont want to write every category condition in .htaccess file?
Thus it will be like, if someone calls url like http://example.com/category, it will be redirected to file in "subfolder" but "subfolder" wont appear in url like this, {host_name}/category. Can this be done?
Example:
{domain}/subfolder/category => {domain}/category
Thus subfolder will be removed.
Please help. Thanks in advance.
In the www_root .htaccess, put…
RewriteEngine On
RewriteBase /
RewriteRule ^subfolder\/(.*) $1
I think that should do it.
I'm not sure how to explain this problem so the title is kind of vague!
Well here I go, I'm working on a picture/album page on my website and everything is working great. But I want to add a next/previous picture feature like any good picture website has. I want to passe the different options for sorting out the album by variables.
For now the url on a picture is http://localhost/photo/174/picture-name/, I would like to add on this some parameters so that the url then looks like http://localhost/photo/174/picture-name/album:5/sort:name/.
With the help of .htaccess I would like to extract the variables album and sort`.`But the little catch is that I would still want to be able to get to the page with only this urlhttp://localhost/photo/174/picture-name/``
For now my .htaccess file looks like this :
RewriteEngine on
RewriteRule ^photo/([A-Za-z0-9]+)/(.*)/$ photo.php?pic_id=$1
I tried adding this line in it but it did not work out.
RewriteRule ^(.*)/album:([A-Za-z0-9]+)/sort:([A-Za-z0-9]+)/$ &album=$2&sort=$3
I hope someone has an answer for me,
Have a good day
Joris
Did you mean something like this?
RewriteRule ^photo/([A-Za-z0-9]+)/[^/]+/album:([A-Za-z0-9]+)/sort:([A-Za-z0-9]+)/$ photo.php?pic_id=$1&album=$2&sort=$3
You also need to change your original rule:
RewriteRule ^photo/([A-Za-z0-9]+)/([^/]*)/?$ photo.php?pic_id=$1
Because what you have will match against the URI with the parameters
I guess you are talking about this, and your example wasn't correct:
RewriteRule ^photo/(.*)/.*/album:(.*)/sort:(.*)/$ photo.php?pic_id=$1&album=$2&sort=$3
(for simplicity, I replaced some of the expressions).
Here, http://mydomain.com/photo/174/picture-name/album:5/sort:name/ get rewritten to http://mydomain.com/photo.php?pic_id=174&album=5&sort=name .
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 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.