Community @ The Turning Gate

Support community for TTG plugins and products.

NOTICE

The Turning Gate's Community has moved to a new home, at https://discourse.theturninggate.net.

This forum is now closed, and exists here as a read-only archive.

  • New user registrations are disabled.
  • Users cannot create new topics.
  • Users cannot reply to existing topics.

You are not logged in.

#1 2018-11-20 06:36:38

mindstorm
Member
Registered: 2014-07-21
Posts: 94

Rewrite Engine needed in .htaccess?

I am trying to do a page redirect on my site, to create a short url to publish in a printed pamphlet, rather than the much longer actual url.  I therefore put the following line in the .htaccess file:

     Redirect 301 /travel /gallery/gallery-travel/

It fails, because it is redirected with some arguments ("/?mod_rewrite=on&page=travel") that seems to mess it up.  If I delete those arguments, then the url is correct.

With some experimentation, I found that if the "Rewrite Engine" part of the .htaccess file is removed, then my redirect works exactly correct.

QUESTION -- Is there some Backlight2 need for this section? Can I just delete it without unwanted side effects?

Just in case it is not clear what section I am referring to, here is the code currently in the .htaccess that is interfering:

<IfModule mod_rewrite.c>
    RewriteEngine On

    ############################################################################
    # Edit this section for servers using FastCGI

    # For FastCGI (or seeing the error message 'No input file specified.':
    # add # to the start of the next line
    RewriteBase /

    RewriteCond $0#%{REQUEST_URI} ([^#]*)#(.*)\1$

    # For FastCGI (or seeing the error message 'No input file specified.':
    # add # to the start of the next line and remove # from the line after)
    RewriteRule ^.*$ - [E=BASE:%2]
    #RewriteRule ^(.*)$ - [E=BASE:]

    ############################################################################



    RewriteRule ^(.*)$ - [E=QS:mod_rewrite=on]

    RewriteRule ^([^\/.]*)-single.php$ %{ENV:BASE}single.php?%{ENV:QS}&id=$1 [QSA,L]

    RewriteRule ^([^\/.]*).css$ %{ENV:BASE}index.php?%{ENV:QS}&extension=css&name=$1 [QSA,L]
    RewriteRule ^([^\/.]*).js$ %{ENV:BASE}index.php?%{ENV:QS}&extension=js&name=$1 [QSA,L]
    RewriteRule ^([^\/.]*).gif$ %{ENV:BASE}index.php?%{ENV:QS}&extension=gif&name=$1 [QSA,L]
    RewriteRule ^([^\/.]*).png$ %{ENV:BASE}index.php?%{ENV:QS}&extension=png&name=$1 [QSA,L]
    RewriteRule ^([^\/.]*).jpg$ %{ENV:BASE}index.php?%{ENV:QS}&extension=jpg&name=$1 [QSA,L]

    #RewriteCond %{QUERY_STRING} !mod_rewrite=on
    #RewriteRule ^index.php$ %{ENV:BASE}index.php?%{ENV:QS} [QSA,L]

    RewriteCond %{QUERY_STRING} !mod_rewrite=on
    RewriteRule ^mobile.php$ %{ENV:BASE}mobile.php?%{ENV:QS} [QSA,L]

    RewriteCond %{QUERY_STRING} !mod_rewrite=on
    RewriteRule ^(.*)download.php %{ENV:BASE}download.php?%{ENV:QS} [QSA,L]
   
    RewriteRule ^$ %{ENV:BASE}index.php?%{ENV:QS} [QSA,L]
   
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d

    RewriteRule ^(.*)$ %{ENV:BASE}index.php?%{ENV:QS}&page=$1 [QSA,L]

</IfModule>

Offline

#2 2018-11-20 14:54:03

rod barbee
Moderator
From: Port Ludlow, WA USA
Registered: 2012-09-24
Posts: 17,830
Website

Re: Rewrite Engine needed in .htaccess?

My guess is that the code in the file is there for a reason.
If you want a shorter url, why not use one of the url shortening services like bitly?

Another approach is to embed the album into a page named travel.


Rod 
Just a user with way too much time on his hands.
www.rodbarbee.com
ttg-tips.com, Backlight 2/3 test site

Offline

#3 2018-11-20 18:07:41

Ben
Moderator
From: Melbourne, Australia
Registered: 2012-09-29
Posts: 4,399

Re: Rewrite Engine needed in .htaccess?

This rule should do what you need, added directly under RewriteEngine On:

RewriteRule ^travel$ http://yoursite.com/gallery/gallery-travel/ [R=301,L] 

Change yoursite.com to your actual site URL.  I've tested this, and the other .htaccess rules still work as expected.

Offline

#4 2018-11-21 01:19:54

mindstorm
Member
Registered: 2014-07-21
Posts: 94

Re: Rewrite Engine needed in .htaccess?

rod barbee wrote:

My guess is that the code in the file is there for a reason.
If you want a shorter url, why not use one of the url shortening services like bitly?

Another approach is to embed the album into a page named travel.

The bitly isn't what I want, since those are full of gobbledygook and hard to remember or type.  Remember, this is so that I can print an easily memorable url in a show brochure.

My first thought was a page at the target location ("/travel") that just had an HTML redirect. However, my reading said that it was considered the least desirable for a bunch of reasons that I no longer remember.  Each of the sites I went to said the .htaccess redirect was the cleanest, so is the way I went with.

As for creating a duplicate page -- that would work today, but has too much risk of quickly getting out of sync, since all these galleries are fluid as we travel more and have other events to track.

Thanks for your suggestions, but it looks like Ben came up with the solution that I will be using this time.

Offline

#5 2018-11-21 01:21:50

mindstorm
Member
Registered: 2014-07-21
Posts: 94

Re: Rewrite Engine needed in .htaccess?

Ben wrote:

This rule should do what you need, added directly under RewriteEngine On:

RewriteRule ^travel$ http://yoursite.com/gallery/gallery-travel/ [R=301,L] 

Change yoursite.com to your actual site URL.  I've tested this, and the other .htaccess rules still work as expected.

THANKS!  I've just put that into my .htaccess and it works like a charm.  I ended up putting 5 lines in there, so there is now a shortcut for each of the main gallery categories.

Now that I have used your solution, and found it works, I guess I need to do some reading to see what this RewriteRule is all about, and why this line works at all... smile

Offline

#6 2018-11-21 04:57:24

Ben
Moderator
From: Melbourne, Australia
Registered: 2012-09-29
Posts: 4,399

Re: Rewrite Engine needed in .htaccess?

I’m glad that worked. I suspect that with your initial approach the .hfaccess file continued to do additional processing after the 301 line. By using RewriteRule, there’s the opportunity to tell the web server to stop processing further rules after that rule matches. That is what the “L” in the square brackets does.

Offline

Board footer

Powered by FluxBB