Hi and sorry for bothering you, i try to look around but i couldn't find a solution, and i really can't figure out how and if it's possible to do something like that with rewriterule.
This is the portion of htaccess file interested in my problem:
RewriteRule ^pagename/([^/]+)-([^/]+) mypage.php?name=$1&id=$2 [NC,L]
example.com/mypage/dogarticle-800ad43
so my variable in php will be like
$_GET["name"]=dogarticle and $_GET["name"]=800ad43
so far so good, but if an article contain a slash i can't get the right variable anymore, example
example.com/mypage/animals/dogandcat-800ad44
where animals/dogandcat should be name i receive the following get vars:
$_GET["name"]=animals $_GET["name"]=dogandcat
Here the question what should i do to receive the following get var:
$_GET["name"]=animals/dogandcat $_GET["name"]=800ad44>
Cant really figure out the solution, probably not the best of my days.
Thanks
edit:
in the name there can be a lot of slash example:
example.com/mypage/animals/dogandcat/squirrel/someotheranimal-800ad44
You can use:
RewriteRule ^pagename/(.+)-([^/]+)$ mypage.php?name=$1&id=$2 [NC,L]
Related
I'm trying to clean my URLs from this:
https://cocrele.com/service-areas/?state=kentucky&city=asher
to this:
https://cocrele.com/service-areas/kentucky/asher/
RewriteEngine On
RewriteRule ^/?service-areas/([^/]+)/([^/]+)/(.+)$ /index.php?eid=$1&cat=$2 [L,QSA]
How would I fix this and how does my code need to be within the page? I currently have this:
echo '<a class="gCity" href="https://cocrele.com/service-areas/?state='.$lowercase_n_state.'&city='.$string_city2.'">'.$array['geoplugin_place'].', '. $array['geoplugin_region'].'</a>';
What the question mark does, is pass variables to your view. This is a nice way to fetch info from the user. You can read about it here and here
If you wanted to remove the "?" from the url, you will need to tell php where to find the variables. Your question is a potential duplicate of this question, so I'd check there for the answer.
I have been trying & searching alot but couldn't find any solution for i have tried many things in .htaccess
My website's Url
mysite.org/torrents.php
To this
mysite.org/Browse
This
mysite.org/torrents.php?parent_cat=Movie
to this
mysite.org/Movie
This
mysite.org/account-details.php?id=737
to this
mysite.org/user/username
Your links won't all work properly, i.e. the /user/username one won't work to an ID number, you could pass the username through then do a lookup based on the username, but htaccess won't know that username "tim" is id number "123"
This should work:
RewriteEngine On
RewriteRule "user/([0-9]*)" account-details.php?id=$1
RewriteRule "category/([a-zA-Z0-9_-]*)" torrents.php?parent_cat=$1
RewriteRule "browse" torrents.php
RewriteRule "" torrents.php
With that I've separated out the categories into a subfolder called 'category' this makes it far easier to allow any category name you want.
For the regular expression matches in the RewriteRules theres an excellent free program called 'Expresso' that will help you build up regular expressions and test them against a list of values to see if they match, I'd recommend searching for it and getting a copy as it's very handy.
Also for the username part if you wanted to do username instead of user ID numbers, then swap:
RewriteRule "user/([0-9]*)" account-details.php?id=$1
to this:
RewriteRule "user/([a-zA-Z0-9_-]*)" account-details.php?username=$1
Try using this. it is a htaccess generator. If this doesn't work you will need to check you php.ini settings to see if it allows this type of link.
We're trying to migrate our forum to another platform and we have encountered links which have queries in them, such as
http://forum.test/threads/119312-Warnight-CS-GO?p=2306618&viewfull=1#post2306618
which has to point to http://forum.test/threads/warnight-cs-go.119312/#post-2306618
So the logical structure of the original link is :
http://{forum_base_url}/threads/{thread-id}-{thread-permalink}?p={post-id}&viewfull={post-number-in-thread}#post{post-id}
While the new one is:
http://{forum_base_url}/threads/{thread-permalink}.{thread-id}/#post-{post-id}
So for the rewrite to work we need to "pull" three things out of the original link: the thread-id, the permalink, and the post-id. The first two aren't an issue, it's the third one which doesn't want to cooperate.
After scouring the Internet for possible solutions, we came up with:
RewriteCond %{QUERY_STRING} ^p=(\d+)&viewfull=(\d+)#post(\d+)$
RewriteRule ^threads/([0-9]+)-(.*)$ /threads/$2\.$1/#post-%1? [R=301,NC,L]
But unfortunately, the rewrite doesn't work.
What throws us off regarding the rewrite is that there are multiple variables in the query and no .php file specified in the link itself, so we can't just use the solution offered here: https://stackoverflow.com/a/2252242/1288397
Any tips on how to overcome this particular hurdle?
The #post- part of the URL is never sent to the server, it remains entirely on the browser's end, so there's no way to match against it. Luckily, the post ID is already in the query string so you can ignore it:
RewriteCond %{QUERY_STRING} ^p=(\d+)&viewfull=(\d+)$
RewriteRule ^threads/([0-9]+)-(.*)$ /threads/$2\.$1/#post-%1? [R=301,NC,L]
The other thing is that the thread-permalink is lowercase in your second URL. Not sure if that matters or not, but in order to change text to lowercase, you need to use a Rewrite Map, and the tolower internal function. You can only declare maps in the server vhost/config, so if you don't have access to those config files, you're not going to be able to use maps.
Thanks for clearing up the #post- aspect.
I tried your modification, but the links initially became:
http://forum.test/threads/warnight-cs-go.119312/%23post-2306618#post2306618
In order to work, the rewrite needs to be
RewriteCond %{QUERY_STRING} ^p=(\d+)&viewfull=(\d+)$
RewriteRule ^threads/([0-9]+)-(.*)$ /threads/$2\.$1/#post-%1? [R=301,NC,NE,L]
Notice the additional NE (noscape) flag at the end
That's because, by default, special characters, such as & and ?, will be converted to their hexcode equivalent. Using the [NE] flag prevents that from happening, as seen here: http://httpd.apache.org/docs/2.2/rewrite/flags.html#flag_ne
I'm currently trying to add a second get variable to an existing htaccess rule. I have little experience with the htaccess but using what expressions I know, I think it's missing one element to ensure the second variable is outputted correctly.
The domain (as the user sees it);
http://domain.com/london-area-info/?src=go
The rule i'm trying to apply;
RewriteRule ^(.*)-area-info/(.*)$ regioncc.php?region=$1&src=$2
The resulting output URL;
http://domain.com/regioncc.php?region=london&src=
I appreciate I'm probably overlooking something but looking around I haven't found an explanation has to how to make sure the ?src=go is shown after the rewrite rule rather than in another directory like /xxx-area-info/src/ for example.
EDIT
I have also tried the following rule but wasn't sure if I was escaping correctly
RewriteRule ^(.*)-area-info/(\?src=?.*)?$ regioncc.php?region=$1&src=$2
I believe this is what you want:
RewriteRule ^(.*)-area-info regioncc.php?region=$1&%{QUERY_STRING}
I am having a lot of trouble getting my php querys re-written to any sort of seo friendly url.
I want to get
http://example.com/provider_list/Dublin.html from the url below
http://example.com/provider_list.php?locationName=Dublin&checkIn_Date=09%2F07%2F2012&checkOut_Date=10%2F07%2F2012&extratype=1&noofextra=1&x=50&y=21
And the same for all other locations
e.g.
provider_list/Wexford.html
So if the query includes the "locationName=ANYLOCATION" it would re write it to this...
It shouldn't matter what the values are for the other names in the query string ...
Is this possible through .htacess?
All help gratefully recieved..
Try this:
RewriteEngine on
RewriteRule provider_list/(\w+).html /locationName=$1&checkIn_Date=09%2F07%2F2012&checkOut_Date=10%2F07%2F2012&extratype=1&noofextra=1&x=50&y=21 [L]
But this is not elegant solution with such long query string, is it necessary?