Welcome to WebmasterWorld Guest from 54.198.164.83

Forum Moderators: Ocean10000 & incrediBILL & phranque

htaccess redirect and htaccess paths.

     
5:37 pm on Dec 16, 2017 (gmt 0)

Junior Member

Top Contributors Of The Month

joined:Nov 29, 2015
posts: 67
votes: 16


Hi all!

I'm trying to redirect some pages that have moved - I have added this line into my htaccess Redirect 301 /old-page /new-page -- but it's redirecting like this http://www.example.com/new-page/?t=old-page So it is working - but adding the old-page as a query string. Here is my htaccess:
Options -Indexes
ServerSignature Off

Redirect 301 /old-page /new-page

RewriteEngine On

SetOutputFilter DEFLATE
#SetEnvIfNoCase Request_URI \.mp4$ no-gzip dont-vary
SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png|swf|mp4|exe|zip|wav|)$ no-gzip dont-vary

RewriteRule ^(html5|index\.php|editor) - [L]
RewriteRule ^.*\.(css|txt)$ - [L]
#RewriteRule ^.*\.(css)$ - [L]

RewriteRule ^(([a-z0-9\-]+/)*[a-z0-9\-]+)$ http://www.example.com/$1/ [R=301,L]

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

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?t=$1 [L,QSA]


Thanks so much to anyone who can help!

Kind regards,
7:22 pm on Dec 16, 2017 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month

joined:Apr 9, 2011
posts:14608
votes: 598


Do not use mod_alias (Redirect by that name) in combination with mod_rewrite (RewriteRule). Things will execute in the wrong order and there will be unintended consequences. Change your redirects to mod_rewrite syntax and report back.
7:32 pm on Dec 16, 2017 (gmt 0)

Administrator from US 

WebmasterWorld Administrator not2easy is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Dec 27, 2006
posts:3678
votes: 205


Short answer - "Redirect uses mod_alias" which may not work as intended when the htaccess file uses mod_rewrite rules also.

If possible, change the old-page -->new-page to a rewrite rule. There are a lot of discussions about combining the two apache modules and from those I've seen that it can work in some cases. Since often it won't work, that seems the easiest place to start.
12:41 am on Dec 17, 2017 (gmt 0)

Administrator

WebmasterWorld Administrator phranque is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Aug 10, 2004
posts:11235
votes: 126


https://httpd.apache.org/docs/current/mod/mod_alias.html#redirect
Additional path information beyond the matched URL-path will be appended to the target URL.
...
This includes requests with GET parameters, ...


https://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewriterule
Modifying the Query String

By default, the query string is passed through unchanged. You can, however, create URLs in the substitution string containing a query string part. Simply use a question mark inside the substitution string to indicate that the following text should be re-injected into the query string. When you want to erase an existing query string, end the substitution string with just a question mark. To combine new and old query strings, use the [QSA] flag.