0

Like on the title, I'm looking for a way to change a url with parameters (from this www.animevid.net/player/?anime=d/dmc to this www.animevid.net/player/anime/d/dmc) using the .htaccess file.

I've found many similar post but I've only got errors, loop redirect, or...nothing. The nearest thing i've got is this code :

RewriteRule ^player/([0-9a-zA-Z_-]+)/([0-9a-zA-Z_-]+) player/index.html?anime=$1&t=$2 [NC,L]

Also please note the "d/dmc" on "?anime=d/dmc", is a variable, another example is "c/codegeass", "s/sao" etc...

6
  • You cannot "hide" parameters. Then they would be missing in your call. A URL is not a magical wand. Commented Aug 8, 2015 at 20:12
  • ok, really thanks, didn't know, post edited Commented Aug 8, 2015 at 20:13
  • Also note that www.animevid.net/player/?anime=d/dmc is not a valid url. Probably it will often work, since clients and servers try to be fault tolerant. But the / in the d/dmc must be encoded in a URL. This is probably your primary issue here. How do you want to catch the d/dmc with that pattern [0-9a-zA-Z_-]+? That cannot work... Commented Aug 8, 2015 at 20:29
  • I need the "x/xxx" cause inside player/index.html there's a script that change an iframe source path based on that variable, do you have any tips or you suggest me to leave this rewrite thing ? Thanks for your help anyway. Commented Aug 8, 2015 at 20:34
  • You miss understood that. Nothing speaks against handing over the / inside an argument. But it has to be escaped, otherwise it has another meaning. See the correct URL I posted in my answer below. What you receive on the server side (inside php for example) is the / you desire with such encoding. Commented Aug 8, 2015 at 20:36

1 Answer 1

1

As mentioned above the final, rewritten url you give as an example is invalid. You should escape the last /:

https://www.animevid.net/player/anime/d%2Fdmc

and rewrite to:

https://www.animevid.net/player/?anime=d%2Fdmc

Then you have to change your regex strategy for this to work. Try something like that:

RewriteEngine On
RewriteRule ^player/([^/]+)/([^/]+) player/index.html?anime=$1&t=$2 [NC,L]
Sign up to request clarification or add additional context in comments.

3 Comments

ok, i'll try that, but i was thinking; what if instead of a url with a single parameter, i had 2 parameter (d and dmc), so then i could fix the script of my iframe, would be it better/easier to achieve the url rewriting im looking for ?
Certainly that is possible, at least if you really can guarantee that that "twin parameter" always has that form. But why do you want to split a parameter in two? You have to urldecode() get parameters anyway inside a script.
This way i could use the "d" parameter or whatevere it is, for more things i could implement later

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.