Page 1 of 2 12 Last
  • Jump to page:
    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2012
    Posts
    9
    Rep Power
    0

    Another newbie question regarding RewriteRule


    Hello folks!

    This is my first post here, my name is Gus and I'm from Brazil.

    I have a website and I need to add a RewriteRule on it. The problem is that I'm a complete newbie on this subject, so I will need some help from you.

    The first thing that I need is to redirect everyone that goes to my website to a file inside a folder.

    I asked my website host to add a DirectoryIndex but they said it is not possible (insecure) and told me to do that by RewriteRule.

    So every time that someone type my web address, he need to goes to /folder/file.php

    But is not that simple, because I also need that when someone clicks on my banners, I receive the strings from Google URL Builder.

    And there is more: my website allows the user to make its own URL, like mydomain.com/user so I already have this RewriteRule:

    ^/([a-z,0-9,A-Z,_-]+)$
    flag: Continue (last) /myhotsite.php?ID=$1

    So let me try to explain in topics:

    1) mydomain.com -> /folder/file.php
    2) mydomain.com/?utm_source=blablabla -> /folder/file.php/?utm_source=blablabla
    3) mydomain.com/* -> nothing happens, no redirect, it keeps my current rewrite rule that goes to /myhotsite.php?ID=$1

    In case 2, I need to keep the query strings, that will go to Google Analytics (as long as I'm concerned, I need to use QSA, but not sure how to)

    So, how do you think that we can solve this in the easiest way?

    And which rule will have priority: the one that I already have or the one that you will help me to create?

    Thanks a lot in advance!

    Best regards,
    Gus
  2. #2
  3. Transforming Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,234
    Rep Power
    9400
    DirectoryIndex (a) can be used inadvertently to create a security hole yes, but that requires a hole somewhere else before it can be used, and (b) wouldn't help in this situation because it can only specify filenames while you need a directory path too.

    That "RewriteRule" you posted isn't the raw directive used to make it work. Are you using some sort of tool to manage them? Can you just edit the .htaccess file directly? Is there even one to use (as opposed to having the directives saved somewhere else you can't access)?
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2012
    Posts
    9
    Rep Power
    0
    Originally Posted by requinix
    That "RewriteRule" you posted isn't the raw directive used to make it work. Are you using some sort of tool to manage them?
    What really makes it work is the rewriterule added to the PHP file. They work together.

    myhotsite.php handle the query, does a MySQL search based on it, get the info and makes the "redirect" (actually, all sites are equal, the only thing different is the info showed)



    [QUOTE=requinix]Can you just edit the .htaccess file directly?
    No, I can't. Nothing happens when I edit the htaccess directly. I have to add the rewrite rules at the control panel.



    Originally Posted by requinix
    Is there even one to use (as opposed to having the directives saved somewhere else you can't access)?
    I bag your pardon, but I could not understand this sentence.



    PS: I don't know if this makes any difference, but my website is running on nginx.
  6. #4
  7. Transforming Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,234
    Rep Power
    9400
    Originally Posted by gscrmn
    What really makes it work is the rewriterule added to the PHP file. They work together.
    That's not where they go... Can I assume you're talking about the redirection the script does according to the ID? And not the actual mechanism that converts URLs like /abc into /myhotsite.php?ID=abc?

    Originally Posted by gscrmn
    No, I can't. Nothing happens when I edit the htaccess directly. I have to add the rewrite rules at the control panel.
    Sounds like the directives are being saved somewhere besides a .htaccess file. Unfortunate.

    Originally Posted by gscrmn
    I bag your pardon, but I could not understand this sentence.
    I was wondering if there actually is a .htaccess file available for editing. You said there is not (well, you can create one, but it doesn't affect anything).


    Originally Posted by gscrmn
    PS: I don't know if this makes any difference, but my website is running on nginx.
    It does. Or rather it should make a difference. nginx doesn't use RewriteRules - that's only Apache. It's sounding more and more like the setup isn't as simple as having an Apache server and a .htaccess file.
    That's fine so long as you have the ability to do URL rewriting somewhere. If this control panel has all the required features (seems like it does) then that should be sufficient.
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2012
    Posts
    9
    Rep Power
    0
    Originally Posted by requinix
    That's not where they go... Can I assume you're talking about the redirection the script does according to the ID? And not the actual mechanism that converts URLs like /abc into /myhotsite.php?ID=abc?
    The Rewriterule that I have mentioned at the OP makes /abc into /myhotsite.php?ID=abc

    Then, myhotsite.php handles the "abc" query, make a MySQL consult, get the necessary info and build SESSION variables.

    After that, it goes to /hotsite, where I file read the variables and mount the webpage based on it.

    So every /abc, /def, /ghi goes to /hotsite



    Originally Posted by requinix
    Sounds like the directives are being saved somewhere besides a .htaccess file. Unfortunate.
    When I add a RewriteRule on the control panel, the .htaccess does not change. So, I also think that the directives are being saved somewhere else.

    Originally Posted by requinix
    I was wondering if there actually is a .htaccess file available for editing. You said there is not (well, you can create one, but it doesn't affect anything).
    There is a .htaccess file on the root directory but nothing happens when I edit it.



    Originally Posted by requinix
    It does. Or rather it should make a difference. nginx doesn't use RewriteRules - that's only Apache. It's sounding more and more like the setup isn't as simple as having an Apache server and a .htaccess file.
    That's fine so long as you have the ability to do URL rewriting somewhere. If this control panel has all the required features (seems like it does) then that should be sufficient.
    For me, it looks like its possible to do "everything" on the control panel. I already have added some rules there and it worked well.
  10. #6
  11. Transforming Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,234
    Rep Power
    9400
    Then this isn't an Apache question anymore...

    But whatever. To address #1 and #2 you'd use simply
    Code:
    RewriteRule ^$ folder/file.php [L]
    Thus an "empty" URL (ie, the homepage) goes to that folder/file.php. It'll get the query string automatically.

    So... translate that into whatever the tool wants.
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2012
    Posts
    9
    Rep Power
    0
    requinix, thanks for your cooperation.

    I made a test and the links at folder/file.php are not pointing correctly.

    I mean, the links where supposed to be /folder/link but they are just /link

    ie
    domain.com/folder/file1.php is pointing to domain.com/file1.php

    Anyway to correct this with Rewriterule, without having to edit the links inside file.php?

    Thanks a lot again!!!
  14. #8
  15. Transforming Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,234
    Rep Power
    9400
    Not sure what you mean by "pointing" but

    Apache cannot change the outbound URLs. The ones you put in your HTML. It can only take incoming requests and reroute/redirect them someplace else. If you are outputting links that look like
    Code:
    <a href="/file1.php">Supposed to go to /folder/file1.php</a>
    then those will not be affected. Apache will get a request for /file1.php and unless it [R]edirects the address bar will say "/file1.php". If you want it to say "/folder/file1.php" then you need to [R]edirect, but even better would be to fix the links so that they go to the right place.
  16. #9
  17. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2012
    Posts
    9
    Rep Power
    0
    requinix,

    The RewriteRule goes to /folder/file.php

    Inside this file are tons of codes like

    Code:
    <a href="/file1.php">That really goes to /folder/file1.php</a>
    It works well without Rewriterule because the file is inside the /folder and "pointing" to /file1.php so the whole path is /folder/file1.php

    The problem occurs when I use the Rewrite.

    The address bar show /file1.php as you said.

    I tried to add a R=301 at the end of the rule, but nothing changed. The problem persists.
  18. #10
  19. Transforming Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,234
    Rep Power
    9400
    Originally Posted by gscrmn
    It works well without Rewriterule because the file is inside the /folder and "pointing" to /file1.php so the whole path is /folder/file1.php
    No... There's a leading slash. /file1.php. That means the current folder doesn't matter and it will go to /file1.php - not /folder/file1.php.

    So maybe that changes your understanding of what you have and how it's supposed to work?
  20. #11
  21. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2012
    Posts
    9
    Rep Power
    0
    Sorry, there is no slash, it is

    <a href="file1.php">That really goes to /folder/file1.php</a>
  22. #12
  23. Transforming Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,234
    Rep Power
    9400
  24. #13
  25. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2012
    Posts
    9
    Rep Power
    0
    Originally Posted by requinix
    But the address bar shows "/file1.php"?
    Address bar shows /folder/file1.php when there is no Rewriterule and file1.php when there is
  26. #14
  27. Transforming Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,234
    Rep Power
    9400
    So you have something that redirects from /folder/file1.php to /file1.php?

    Or how about this: what rules do you have in place now?
  28. #15
  29. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2012
    Posts
    9
    Rep Power
    0
    I have no redirects / Rewriterules.

    Today it works pretty fine: the file index.php is located inside folder pub -> pub/index.php

    When I access pub/index.php there are tons of links pointing to files INSIDE this folder, so address bar is like

    pub/file1.php, pub/file2.php, pub/fileN.php

    The problem occurs when I add a Rewriterule, because links changing from pub/fileN.php to fileN.php
Page 1 of 2 12 Last
  • Jump to page:

IMN logo majestic logo threadwatch logo seochat tools logo