SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Enthusiast
    Join Date
    Dec 2007
    Posts
    81
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    .htaccess re-directing to folder within my website?

    How would I tell the search engines that I'm re-directing my URLS to

    http://mydomain.com/autos/1998/Toyota/Camry
    from
    http://www.mydomain.com/1998/Toyota/Camry

    I'm adding in the "autos" in between every vehicle I have on my website.

    How would I account for that ("autos") in my htaccess re-direct?

    Thanks

  2. #2
    SitePoint Wizard bronze trophy Jeff Mott's Avatar
    Join Date
    Jul 2009
    Posts
    1,264
    Mentioned
    18 Post(s)
    Tagged
    0 Thread(s)
    "First make it work. Then make it better."

  3. #3
    SitePoint Enthusiast
    Join Date
    Dec 2007
    Posts
    81
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks Jeff!

  4. #4
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,067
    Mentioned
    153 Post(s)
    Tagged
    2 Thread(s)
    Quote Originally Posted by Jeff Mott View Post
    That is not entirely correct as those examples just use [R], which google sees as a temporary redirect (if not supplied, the status for the [R] flag defaults to 302). If the URL changes indefinitely one should use [R=301], for HTTP status 301.
    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

  5. #5
    SitePoint Enthusiast
    Join Date
    Dec 2007
    Posts
    81
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Thanks for the reply. This is the syntax I came up with. What do you think? Thanks

    Code:
    RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
    RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

  6. #6
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,067
    Mentioned
    153 Post(s)
    Tagged
    2 Thread(s)
    Looks good! I would make one small amendment; use %{REQUEST_URI} instead of (.*) and $1 :

    Code:
    RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
    RewriteRule .? http://%1%{REQUEST_URI} [R=301,L]
    Simply to avoid a regex that's not really needed
    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

  7. #7
    SitePoint Wizard bronze trophy Jeff Mott's Avatar
    Join Date
    Jul 2009
    Posts
    1,264
    Mentioned
    18 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ScallioXTX View Post
    Looks good! I would make one small amendment; use %{REQUEST_URI} instead of (.*) and $1 :

    Simply to avoid a regex that's not really needed
    I'm dubious about this one. Normally, each rewrite rule matches against the output of the previous rewrite rule. If there were no previous rewrite rules, then (.*)/$1 and .?/%{REQUEST_URI} are functionally equivalent. But if there were previous rewrite rules, then the .?/%{REQUEST_URI} construct would throw away that output.

    Presumably, the motivation for .?/%{REQUEST_URI} is that it's supposed to be faster... Time to break out the measurement tools. The difference between the two is 2 nanoseconds. That's about as micro as a micro-optimization will ever get. And to boot, it was the (.*) version that was 2 nanoseconds faster.

    I see only downsides and no upside.
    "First make it work. Then make it better."

  8. #8
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,067
    Mentioned
    153 Post(s)
    Tagged
    2 Thread(s)
    Quote Originally Posted by Jeff Mott View Post
    I'm dubious about this one. Normally, each rewrite rule matches against the output of the previous rewrite rule. If there were no previous rewrite rules, then (.*)/$1 and .?/%{REQUEST_URI} are functionally equivalent. But if there were previous rewrite rules, then the .?/%{REQUEST_URI} construct would throw away that output.

    Presumably, the motivation for .?/%{REQUEST_URI} is that it's supposed to be faster... Time to break out the measurement tools. The difference between the two is 2 nanoseconds. That's about as micro as a micro-optimization will ever get. And to boot, it was the (.*) version that was 2 nanoseconds faster.

    I see only downsides and no upside.
    I stand corrected!
    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


Tags for this Thread

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
  •