1

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

2
  • it looks like you need to clean up your url structuring out side of that you could urlencode your URL so that the / = %2F ie urlencode('animals/dogandcat'); that way you are selecting the right portion of the url Commented Dec 22, 2016 at 17:17
  • thanks for the suggestion, i was also thinking as last resource to do somehing like that php or js side, but i was just wondering if it wasnt possible directly with htaccess Commented Dec 22, 2016 at 17:28

1 Answer 1

1

You can use:

RewriteRule ^pagename/(.+)-([^/]+)$ mypage.php?name=$1&id=$2 [NC,L]
Sign up to request clarification or add additional context in comments.

1 Comment

thanks so much really u saved me for lot of troubles, it's just perfect

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.