• There is an important update regarding account security and 2FA. Please click here for more information.
  • Welcome to PokéCommunity! Register now and join one of the best fan communities on the 'net to talk Pokémon and more! We are not affiliated with The Pokémon Company or Nintendo.
  • Imgur has blocked certain regions from viewing any images uploaded to their site. If you use Imgur, please consider replacing any image links/embeds you may have on PokéCommunity so everyone can see your images. Click here to learn more.

.htaccess

  • 74
    Posts
    20
    Years
    • Seen Sep 5, 2014
    I am currently working on my new layout and site under an /immerse directory, but when everything is done, I am moving it to the root directory (/).

    All of the links I have in this new layout do not use /immerse in their names so that when I move everything to the root directory, everything works (since they will not be in a folder anymore). Unfortunately, I need to be able to click the links while I am working on the layout, so I was wondering if there is a way for .htaccess to add to the beginning of all links /immerse when I use /, and then when I delete the file, all of the links will revert back to /.

    For example, this is a link right now under the /immerse directory:
    https://www.pokebeach.com/sets/fossil
    I want it to change to this with .htaccess:
    https://www.pokebeach.com/immerse/sets/fossil
    Then when I delete the .htaccess and move the immerse folder files into the root directory, it reverts back to:
    https://www.pokebeach.com/sets/fossil
     
    Why don't you just link things like 'sets/fossil' so that they work on both things with no .htaccess messiness?
     
    Try something like

    Code:
    RewriteEngine On
    Options +FollowSymlinks
    RewriteBase /
    RewriteRule ^immerse/(.*)$ - [L]
    RewriteRule ^immerse$ - [L]
    RewriteRule ^(.*)$ immerse/$1 [R=301,L]

    Haven't tested it, but if you play around with it it might work. Basically, it takes anything that already has immerse/whatever, and stops it redirecting; anything else it'll make redirect.
     
    I've never really needed htaccess so i can't give you personal advice. However, I do know of a htaccess tutorial website that may be able to help. Check this link out https://www.htaccesselite.com/htaccess/rewrites-and-redirects-vf4.html
    it links to a forum that deals in htaccess issues n such.

    I found a tut that allows you to redirect failiing links from one server to the next. I don't know htaccess syntax but it seems that you can edit the script to point to the right directory on failing links

    Description:

    A typical FAQ about URL rewriting is how to redirect failing requests on webserver A to webserver B. Usually this is done via ErrorDocument CGI-scripts in Perl, but there is also a mod_rewrite solution. But notice that this performs more poorly than using an ErrorDocument CGI-script!

    Solution:

    The first solution has the best performance but less flexibility, and is less error safe:

    Code:
        RewriteEngine on
        RewriteCond   /your/docroot/%{REQUEST_FILENAME} !-f
        RewriteRule   ^(.+)                             https://webserverB.dom/$1


    The problem here is that this will only work for pages inside the DocumentRoot. While you can add more Conditions (for instance to also handle homedirs, etc.) there is better variant:

    Code:
        RewriteEngine on
        RewriteCond   %{REQUEST_URI} !-U
        RewriteRule   ^(.+)          https://webserverB.dom/$1


    This uses the URL look-ahead feature of mod_rewrite. The result is that this will work for all types of URLs and is a safe way. But it does a performance impact on the webserver, because for every request there is one more internal subrequest. So, if your webserver runs on a powerful CPU, use this one. If it is a slow machine, use the first approach or better a ErrorDocument CGI-script.

    Original Link: https://www.htaccesselite.com/htaccess/redirect-failing-urls-to-other-webserver-vt97.html
     
    Back
    Top