Skip to main content
Inspiring
November 22, 2018
Answered

Using .htaccess to redirect to (or mirror) a folder... am I doing it right?

  • November 22, 2018
  • 1 reply
  • 4231 views

Designer cosplaying as a programmer here (and have been for 10 years), so feel free to dumb down those replies, I won't be insulted.

So here's the thing... I currently have all my landing pages in the domain.com/pages folder. However, I'd like to clean up my urls so that the redundant /pages portion of the url is removed from the user's view, by having domain.com/welcome.php forward to where the actual page is stored, domain.com/pages/welcome.php.

I've run some tests, and a simple...

redirect 301      /welcome.php     /pages/welcome.php

...will accomplish this. And since I don't plan on having more than a dozen pages on this site, I could just do this for each page, on 12 separate lines in the .htaccess file.

However, with this method, the user can see there was a redirect there, because the link they clicked isn't where they ended up.

If there was a way to simply mirror the /pages folder at the root, that would probably solve everything with 1 line. But then, how would files like .htaccess, robots and favicon get read by the browser ? If I did this, would I have to move everything but .htaccess (including robots + favicon) to /pages for the browser to read them? I smell unforeseen complications down the line.

So should I just give up the idea of mirroring (to mask the fact that these are redirects) and just be glad I can redirect with minimal fuss?

Or is there a better way to tell .htaccess to do something like this?

mirror     /welcome.php     /pages/welcome.php

(I know that's not a real thing, just made it up to illustrate what I'm trying to achieve.)

I welcome your advice.

Thanks!

    This topic has been closed for replies.
    Correct answer Nancy OShea

    https://forums.adobe.com/people/Nancy+OShea  wrote

    https://forums.adobe.com/people/Under+S.   wrote

    Chrome has done away with displaying the http/https part altogether

    That's not my experience.  See screenshots from the 3 major browsers.

    You're right, I just went back to check. What was I looking at earlier, then? Maybe I'm just losing my mind. For some reason, I remembered Chrome having the lock symbol instead of the https, rather than in addition to. My mistake.

    Energize seems to believe both www + non-www versions of the url can be secured by Let's Encrypt. So I don't have to choose then? (Other than specifying one of them in "canonical", probably the non-www version)?


    I pay for my certs because I need more than  Let's Encrypt's free certs provide. 

    If you don't have to pay anything, cost is no concern.  Get as many certs as you need.

    I think the www vs non-www question is a little like hanging toilet paper.  Do you hang the flap on the inside or the outside?  You decide which works best for you.

    1 reply

    Nancy OShea
    Community Expert
    Community Expert
    November 22, 2018

    Don't duplicate content.  Google will penalize your for it.

    Get rid of Pages folder.

    Move your files to root level.

    Use a 301 permanent redirect from old URL to new URL.

    301 Redirects | CSS-Tricks

    While you're at it, remove file extensions.

    Instead of yourdomain.com/welcome.php  visitors will see  yourdomain.com/welcome

    That way if you decide to change technologies later, it won't hurt your SEO.

    https://tecadmin.net/remove-file-extension-from-url-using-htaccess/

    Nancy O'Shea— Product User & Community Expert
    Under S.Author
    Inspiring
    November 22, 2018

    https://forums.adobe.com/people/Nancy+OShea  wrote

    Don't duplicate content.  Google will penalize your for it.

    What do you mean by duplicating content? I don't think I mentioned anything about that (at least not consciously.) Mirroring urls shouldn't duplicate the content (only 1 copy of each page).

    Are you suggesting that 2 functioning urls leading to the same page will be penalized by Google? (ie, if both domain.com/pages/page.html and domain.com/page.html take you to the same physical file)

    Get rid of Pages folder.

    Move your files to root level.

    Not really an option, unfortunately. (There's just no way I'm cluttering my root folder by putting all my pages there.)

    The pages are stored in /pages, assembled from various parts via php includes. This is where I've always put them, and am most comfortable manipulating them. Each page is made up of 4-5 includes (the layout is modular and some parts repeat across all pages, so I include them separately).

    Unless there's a better reason to clutter my root folder than "shorter url's" I think I'd rather give up on this altogether than go that route (ie, just leave the redundant /pages portion of the url visible to all).

    I was just wondering if there was a simple way for me to accomplish what I'm trying to do (simple = without completely changing the structure of my website folders).

    Nancy OShea
    Community Expert
    Community Expert
    November 22, 2018

    When one or more URLs go to the same content, it's considered duplicate content. 

    rel=canonical: the ultimate guide to canonical URLs • Yoast

    I think what you want is a Mod_rewrite rule to hide the folder name in URLs. 

    regex - how to remove folder name from url using htaccess - Stack Overflow

    Nancy O'Shea— Product User & Community Expert