Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.
Options

Need Help With Creating Wild Card Routes

edited March 2012 in Vanilla 2.0 - 2.8

I need to create a route so that example.com/cache/Sitemaps/anything.xml is shortened to example.com/anything.xml.

Can anyone help? Thanks!

Best Answer

  • Options
    LeeHLeeH
    Answer ✓

    This is the kind of thing that you should try to do with your web server instead of at the application layer if possible—a redirect or rewrite by the web server will always be faster and use fewer resources than pushing something up and down the php stack! x00's advice to use a rewrite rule in one of your .htaccess files (or in your vhost config) is right on.

Answers

  • Options
    422422 Developer MVP
    edited March 2012

    There was an error rendering this rich post.

  • Options
    edited March 2012

    @422 : Can you please explain? I am not really well versed with .htaccess stuff.

    Here's the thing: example.com/cache/Sitemaps/anything.xml should be shortened to example.com/anything.xml, but example.com/anything.xml itself isn't supposed to redirected anywhere.

    If you know how I can achieve that using Htaccess rewrite, please do share. Thanks!

  • Options
    edited March 2012

    @422 : Thanks for the tool, but it doesn't seem to do wildcard redirects. Maybe I wasn't clear.

    1. example.com/anything.xml does not exist!

    2. I want any file in example.com/cache/Sitemaps/* to be shorted to (not redirected) example.com/*

    3. For example, I should be able to access example.com/cache/Sitemaps/anything.xml from example.com/anything.xml as if the file (anything.xml) is actually present at example.com/.

    Is that possible? I hope I am clear this time.

  • Options
    422422 Developer MVP

    U can do a rewrite so the clickable uri appears like a destination uri

    Eg. We have a fille called twats.php

    We can use rewrite to make it look like a folder.

    Is that what u mean?

    There was an error rendering this rich post.

  • Options

    @422 : No, I mean a wildcard redirect. That is... one rewrite rule that creates aliases for all files in a directory. For example:

    example.com/cache/Sitemaps/file1.xml → example.com/file1.xml
    example.com/cache/Sitemaps/file2.xml → example.com/file2.xml
    example.com/cache/Sitemaps/file3.xml → example.com/file3.xml and so on...

    That's what I meant by a wildcard rewrite rule. Do you know to do it? (It uses something like $1, and stuff that doesn't make sense to me.)

  • Options
    422422 Developer MVP

    x00 will know, he is at one with that shizznit

    There was an error rendering this rich post.

  • Options
    edited March 2012

    @x00 : Need some help when you are here. Thanks!

  • Options
    x00x00 MVP
    edited March 2012

    If you look at my post on sitemaps question I provide the answer to this, I used vanilla routes but you can also use .htacess

    RewriteRule sitemap\.([^\.]+)\.xml$ cache/Sitemaps/sitemap.$1.xml

    the ^ in the square brackets means negative so anything that is not a . (dot) and more than one (+) followed by .xml. This is a typical but not the only way of doing wild card. As regexp is quite specific using negative is a way of caching a lot of characters.

    grep is your friend.

  • Options

    If you look at my post on sitemaps question I provide the answer to this...

    @x00 : Can you please provide a link to that post? Thanks.

  • Options

    can't you search for it? I provided exactly the answer to this question, look at the questions off the sitemaps plugin and you shall find it.

    It get really tedious if I have to dig this stuff up myself.

    grep is your friend.

  • Options
    edited March 2012

    @x00 : you said, "If you look at my post on sitemaps question I provide the answer to this, I used vanilla routes but you can also use .htacess" So I thought, you provided an alternative answer elsewhere.

    I have been searching on (& trying to fix) this issue since morning. Looks like my search terms did not match the question you answered. It's not always easy to 'search' when you don't know the exact search terms to query for. :(

    I try my best on an issue before I ask buddy. :)

  • Options

    look at the questions off the sitemaps plugin and you shall find it.

    grep is your friend.

  • Options
    edited March 2012

    Damn! It didn't strike my head that I could actually follow the 'Sitemaps' tag. Thanks for pointing me in the right direction.

    EDIT: I missed the questions on that page because the page is broken and the questions are quite far below. lol!

  • Options
    LeeHLeeH
    Answer ✓

    This is the kind of thing that you should try to do with your web server instead of at the application layer if possible—a redirect or rewrite by the web server will always be faster and use fewer resources than pushing something up and down the php stack! x00's advice to use a rewrite rule in one of your .htaccess files (or in your vhost config) is right on.

  • Options

    @LeeH : You are right. I did just that. But a choice is always good. So, I was checking both.

  • Options
    422422 Developer MVP

    Cough. Didnt i mention this lol

    There was an error rendering this rich post.

  • Options

    @422 : Isn't the addon's page broken for you? http://vanillaforums.org/addon/sitemaps-plugin

    The questions have been pushed quite far below, which made me think there were no questions at all. I should have checked properly, nevertheless. :P

Sign In or Register to comment.