SitePoint Sponsor

User Tag List

Page 2 of 2 FirstFirst 12
Results 26 to 48 of 48
  1. #26
    SitePoint Wizard bronze trophy PicnicTutorials's Avatar
    Join Date
    Dec 2007
    Location
    Carlsbad, California, United States
    Posts
    3,658
    Mentioned
    15 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Jeff Mott View Post
    The HTTP spec says "Note that the absolute path cannot be empty; if none is present in the original URI, it MUST be given as "/" (the server root)."

    However, whether google also treats an empty path the same as a root path is a different question. I haven't been able to find any statements from google that explicitly says one way or the other. Though, I expect that they would treat them the same, since the HTTP spec treats them the same.

    And just to reiterate, whether google treats them the same or not doesn't change that a rewrite rule can't enforce it. All you can do is be consistent with the way you write your HTML links.
    Here Matt says how google "probably" treats them. http://www.youtube.com/watch?v=CTrdP7lJ2HU using this search "matt cutts trailing slash or not"

    But regardless if the slash is left off the browser redirects to the slash. So it would be better to force the trailing slash before the browser gets it yeah??

  2. #27
    SitePoint Wizard bronze trophy PicnicTutorials's Avatar
    Join Date
    Dec 2007
    Location
    Carlsbad, California, United States
    Posts
    3,658
    Mentioned
    15 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Jeff Mott View Post
    That's again talking about slashes at the end of paths, not at the end of hostnames.

    If you or anyone else can devise a rewrite rule that forces slashes at the end of hostnames, that would be pretty exciting. But everything I know says this isn't possible.
    Would this did it?

    RewriteRule (.*[^/])$ $1/ [R=301,L]

    http://stackoverflow.com/questions/7...-the-same-time

  3. #28
    SitePoint Wizard bronze trophy Jeff Mott's Avatar
    Join Date
    Jul 2009
    Posts
    1,311
    Mentioned
    19 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by EricWatson View Post
    But regardless if the slash is left off the browser redirects to the slash. So it would be better to force the trailing slash before the browser gets it yeah??
    Ish. "Redirect" is probably the wrong word in this case. If you watch the network console, you'll see that there isn't actually a redirect happening. (On the other hand, if you leave the trailing slash off a path directory, then it is redirected, and you can see that redirect in the network console.)

    In theory, it's better to be consistent, and to pick the slash-after-hostname format when writing links. But in practice it makes no difference. There's no performance cost, because browsers will always send the slash anyway, and there's no page rank cost, because google can easily deduce that they're the same resource.

    And getting back to your original requirement... wanting rewrite rules to enforce the slash is moot, because it's still the case that rewrite rules can't enforce this. And since browsers will send the slash either way, the server can't even detect if it's there or not.
    "First make it work. Then make it better."

  4. #29
    SitePoint Wizard bronze trophy Jeff Mott's Avatar
    Join Date
    Jul 2009
    Posts
    1,311
    Mentioned
    19 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by EricWatson View Post
    Would this did it?

    RewriteRule (.*[^/])$ $1/ [R=301,L]

    http://stackoverflow.com/questions/7...-the-same-time
    You probably could have gotten a faster answer if you tried it yourself. But no, that won't do it.
    "First make it work. Then make it better."

  5. #30
    SitePoint Wizard bronze trophy PicnicTutorials's Avatar
    Join Date
    Dec 2007
    Location
    Carlsbad, California, United States
    Posts
    3,658
    Mentioned
    15 Post(s)
    Tagged
    0 Thread(s)
    Ok thanks Jeff. I'll throw the code in tomorrow morning and test it all out. I'll post back with the results. Take care

  6. #31
    SitePoint Wizard bronze trophy PicnicTutorials's Avatar
    Join Date
    Dec 2007
    Location
    Carlsbad, California, United States
    Posts
    3,658
    Mentioned
    15 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Jeff Mott View Post
    For example, in your original rewrite rule, index.html would be stripped from your maindomain URLs, but not from your addondomain URLs. Whereas the new rewrite rule will strip index.html from the URL regardless of the domain. Ditto for the www. Your original rule would not add www to your addon domains, whereas the new rule will.
    Morning

    ok seems to work perfect on the main domain. But doesnt seem to perform as mentioned on the addon domains. Without the code added to htaccess in addon nothing is rewritten as it should be - no www stays no www and domain/index.php remains with the index.php. If I add the code to addon htaccess then the no www is redirect to www but the index is not striped off. What do you think?

    EDIT: forgot to change it to php extensions. Ok so without the code added to the addons httaccess nothing works. With it added it works just like the main. So you said no need to add code to addon htaccess. Just checking how its working. Should I obviuosly add it to the addon htaccesss too then? Or should we edit the code some to include? Thanks!

  7. #32
    SitePoint Wizard bronze trophy Jeff Mott's Avatar
    Join Date
    Jul 2009
    Posts
    1,311
    Mentioned
    19 Post(s)
    Tagged
    1 Thread(s)
    I'm a little confused now how your site is configured. Originally it seemed like your maindomain and addondomains all read from the same htaccess, and that's why you had to exclude the addondomains from your original rewrite rules. But now it sounds like you're saying they each read from their own htaccess...?
    "First make it work. Then make it better."

  8. #33
    SitePoint Wizard bronze trophy PicnicTutorials's Avatar
    Join Date
    Dec 2007
    Location
    Carlsbad, California, United States
    Posts
    3,658
    Mentioned
    15 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Jeff Mott View Post
    I'm a little confused now how your site is configured. Originally it seemed like your maindomain and addondomains all read from the same htaccess, and that's why you had to exclude the addondomains from your original rewrite rules. But now it sounds like you're saying they each read from their own htaccess...?
    Don't ask me lol. Best I can guess is that there is some bleed through. Currently yes each domain has their own htaccess. But as shown my previous rules bled through. Maybe Hostgator has a config file set up that does some magic. As said before my set up is...

    public_html/.htaccess (root main domain)
    public_html/addondomain/.htaccess

  9. #34
    SitePoint Wizard bronze trophy Jeff Mott's Avatar
    Join Date
    Jul 2009
    Posts
    1,311
    Mentioned
    19 Post(s)
    Tagged
    1 Thread(s)
    If you have rewrite rules in your addondomaon htaccess, then that may be overriding the rewrite rules in the root maindomain htaccess.
    "First make it work. Then make it better."

  10. #35
    SitePoint Wizard bronze trophy PicnicTutorials's Avatar
    Join Date
    Dec 2007
    Location
    Carlsbad, California, United States
    Posts
    3,658
    Mentioned
    15 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Jeff Mott View Post
    If you have rewrite rules in your addondomaon htaccess, then that may be overriding the rewrite rules in the root maindomain htaccess.
    No I have no rewrite rules in there. Here is what Hostgator says about addon domains.

    http://support.hostgator.com/article...n-addon-domain

  11. #36
    SitePoint Wizard bronze trophy Jeff Mott's Avatar
    Join Date
    Jul 2009
    Posts
    1,311
    Mentioned
    19 Post(s)
    Tagged
    1 Thread(s)
    It sounds like an addon domain is treated the same as a subdomain, which means different vhost, different document root, and it also means they don't share htaccess with the main domain. But the weird part is that you said your original rewrite rules were redirecting the addon domains to the main domain. But if the addon domains weren't reading the main domain htaccess... were you just copy-pasting the same code to all the htaccess files?

    I suppose the simple option is to keep on copy-pasting if that's what you were doing before. The clever option would be to use <Directory> directives with regular expressions (but you need access to the main server config). And the dirty option would be to create the addon domain htaccess via symbolic link to the main domain htaccess.
    "First make it work. Then make it better."

  12. #37
    SitePoint Wizard bronze trophy PicnicTutorials's Avatar
    Join Date
    Dec 2007
    Location
    Carlsbad, California, United States
    Posts
    3,658
    Mentioned
    15 Post(s)
    Tagged
    0 Thread(s)
    Yeah for the most part I was just repeating the htaccess. Aside from the exclusion line for the addons. Sounds good. Just checking to see if you had any in sites as to the whys. Thanks a lot.

  13. #38
    SitePoint Wizard bronze trophy PicnicTutorials's Avatar
    Join Date
    Dec 2007
    Location
    Carlsbad, California, United States
    Posts
    3,658
    Mentioned
    15 Post(s)
    Tagged
    0 Thread(s)
    Hey Jeff. Looking around the web every other example of this code to strip the index adds another line above your example like so. Is there a reason you removed it? And do you think it's necessary? And what does it do? Thanks!

    Code:
     
    RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*index\.html\ HTTP/
    RewriteRule ^(.*)index\.html$ /$1 [R=301,L]

  14. #39
    SitePoint Wizard bronze trophy Jeff Mott's Avatar
    Join Date
    Jul 2009
    Posts
    1,311
    Mentioned
    19 Post(s)
    Tagged
    1 Thread(s)
    I suspect most examples were copy-pasted from other websites, which were themselves copy-pasted from other websites, and so on. And the people who copy it onto their own website may not even themselves understand the reason for each line.

    Based on things your other guy has said, I suspect that he believes that testing THE_REQUEST is necessary to avoid an infinite loop. Though, it turns out it isn't actually necessary. The rewrite rule I posted has no infinite loop. I had tested it when I first posted, and I tested it again just now.

    The rewrite rule will match only if index.html is at the end of the URL. After it performs the redirect, then index.html will no longer be at the end, and the rewrite rule won't match the second time around. Thus, no infinite loop.
    "First make it work. Then make it better."

  15. #40
    SitePoint Wizard bronze trophy PicnicTutorials's Avatar
    Join Date
    Dec 2007
    Location
    Carlsbad, California, United States
    Posts
    3,658
    Mentioned
    15 Post(s)
    Tagged
    0 Thread(s)
    Thanks Jeff. Yeah I know thats why I'm actually trying to understand. I just pasted your one liner in google and the whole page showed that code i just posted. Aside from checking the request, is it also making sure its letter a-z and numbers 1-9 or something also?

  16. #41
    SitePoint Wizard bronze trophy Jeff Mott's Avatar
    Join Date
    Jul 2009
    Posts
    1,311
    Mentioned
    19 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by EricWatson View Post
    Aside from checking the request, is it also making sure its letter a-z and numbers 1-9 or something also?
    Not exactly. The value of THE_REQUEST will look something like this:

    GET /index.html HTTP/1.1

    The initial letter-matching pattern is meant to match the HTTP method (GET, POST, HEAD, etc.), followed by a space. Once we get into the request path, then the condition matches on .*.
    "First make it work. Then make it better."

  17. #42
    SitePoint Wizard bronze trophy Jeff Mott's Avatar
    Join Date
    Jul 2009
    Posts
    1,311
    Mentioned
    19 Post(s)
    Tagged
    1 Thread(s)
    I think I found your other guy on your other forum. Want me to rebut directly?
    "First make it work. Then make it better."

  18. #43
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,094
    Mentioned
    153 Post(s)
    Tagged
    2 Thread(s)
    This code removed index.html at the end of a URL, so that when people request example.com/index.hml they are 301 redirected to example.com/

    The reason people use THE_REQUEST for this, is because that's the only way you can effectively remove the DirectoryIndex to another place, since the requested URI as far as Apache is concerned is index.html when you request /, leading to an infinite loop of redirects.

    THE_REQUEST shows you the raw headers of the request, i.e., the URL people requested, instead of the URL apache inferred people were requesting.

    Quote Originally Posted by EricWatson View Post
    Hey Jeff. Looking around the web every other example of this code to strip the index adds another line above your example like so. Is there a reason you removed it? And do you think it's necessary? And what does it do? Thanks!

    Code:
     
    RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*index\.html\ HTTP/
    RewriteRule ^(.*)index\.html$ /$1 [R=301,L]
    Rémon - Hosting Advisor

    SitePoint forums will switch to Discourse soon! Make sure you're ready for it!

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy

  19. #44
    SitePoint Wizard bronze trophy Jeff Mott's Avatar
    Join Date
    Jul 2009
    Posts
    1,311
    Mentioned
    19 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by ScallioXTX View Post
    ...since the requested URI as far as Apache is concerned is index.html when you request /, leading to an infinite loop of redirects.
    Did you actually try it to confirm? Because I don't get any redirect loop.

    EDIT: And the reason why there's no loop seems to be because when mod_dir handles the request, mod_rewrite isn't run.
    "First make it work. Then make it better."

  20. #45
    SitePoint Wizard bronze trophy PicnicTutorials's Avatar
    Join Date
    Dec 2007
    Location
    Carlsbad, California, United States
    Posts
    3,658
    Mentioned
    15 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Jeff Mott View Post
    I think I found your other guy on your other forum. Want me to rebut directly?
    Sure feel free http://www.webmasterworld.com/apache/4562115.htm I hate to pit your two minds against each other but my need to get to the bottom of this is greater. I wish I could participate in the discussion. But I'm afraid I will never fully get this stuff. I'm guessing you already jumped in?

  21. #46
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,094
    Mentioned
    153 Post(s)
    Tagged
    2 Thread(s)
    Quote Originally Posted by Jeff Mott View Post
    Did you actually try it to confirm? Because I don't get any redirect loop.

    EDIT: And the reason why there's no loop seems to be because when mod_dir handles the request, mod_rewrite isn't run.
    Right, I was confusing index.html via mod_dir with index.php served via RewriteRule ("catch-all"); in the latter case you DO need to use THE_REQUEST if you want to redirect away from index.php.

    But indeed, in the case of index.html I have no idea why one would use THE_REQUEST.
    Rémon - Hosting Advisor

    SitePoint forums will switch to Discourse soon! Make sure you're ready for it!

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy

  22. #47
    SitePoint Wizard bronze trophy PicnicTutorials's Avatar
    Join Date
    Dec 2007
    Location
    Carlsbad, California, United States
    Posts
    3,658
    Mentioned
    15 Post(s)
    Tagged
    0 Thread(s)
    Ahh shes a quick one.

    "" It's unusual to meet such a vigorous defense of inefficient rules and careless coding. Can't help but wonder if there's a backstory we're not getting. ""

    I'll come clean over there. But I do not feel bad because they refused to answer my original question I proposed to you with 3 weeks ago about auto non redirects to addon domains. And they refused to answer I suspect because there is no answer using their preferred method of thinking.

  23. #48
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,094
    Mentioned
    153 Post(s)
    Tagged
    2 Thread(s)
    Since you seem to have taken the thread over to the other forum I don't think this one is needed anymore.

    Thread closed.
    Rémon - Hosting Advisor

    SitePoint forums will switch to Discourse soon! Make sure you're ready for it!

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •