SEO Redirects 5, 6, 7, 8 and 9 to home page Topic is solved

Discuss Search Engine Optimization in relation to Joomla! 3.x. This forum will also have discussions on SEF/SEO Joomla! 3.x extensions.

Moderator: General Support Moderators

Forum rules
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting, this means YOU.
Forum Post Assistant - If you are serious about wanting help, you will use this tool to help you post.
Post Reply
davegattis
Joomla! Fledgling
Joomla! Fledgling
Posts: 3
Joined: Tue Oct 30, 2018 12:53 pm

SEO Redirects 5, 6, 7, 8 and 9 to home page

Post by davegattis » Wed Oct 31, 2018 2:10 am

Hey gang,

Maybe you've seen this, maybe not. I'm hoping someone has and has a fix for it.

https://mydomain.com/0, 1, 2, 3 or 4 and any additional characters produces a 404 error. Correct!
https://mydomain.com/5, 6, 7, 8 or 9 and any additional characters sends me to index.php (home page). Incorrect.

Note:
I have tried replacing my .htaccess file with the "outofthebox" version and get the same results.
I have included my own .htaccess file below to show what I'm doing.

In both cases, I load the file, then shut down and restart Apache after I clear the Joomla cache.

I have checked all settings reported in the Forum Post Assistant and found nothing that would be causing this.

Hopefully I'm not the only person who's ever seen this and there is a quick fix for it.

My environment?

Apache 2.4.18
PHP: 7.0.32
Joomla: 3.8.13 Stable

Here's my .htaccess file:

##
# @package Joomla
# @copyright Copyright (C) 2005 - 2016 Open Source Matters. All rights reserved.
# @license GNU General Public License version 2 or later; see LICENSE.txt
##

##
# READ THIS COMPLETELY IF YOU CHOOSE TO USE THIS FILE!
#
# The line 'Options +FollowSymLinks' may cause problems with some server configurations.
# It is required for the use of mod_rewrite, but it may have already been set by your
# server administrator in a way that disallows changing it in this .htaccess file.
# If using it causes your site to produce an error, comment it out (add # to the
# beginning of the line), reload your site in your browser and test your sef urls. If
# they work, then it has been set by your server administrator and you do not need to
# set it here.
##

## No directory listings
IndexIgnore *

## Can be commented out if causes errors, see notes above.
Options +FollowSymlinks
Options -Indexes

## Mod_rewrite in use.

RewriteEngine On
RewriteCond %{HTTP_HOST} ^blah01.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.blah02.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.blah03.com$ [OR]
RewriteCond %{HTTP_HOST} ^blah02.com$ [OR]
RewriteCond %{HTTP_HOST} ^blah03.com$ [OR]
RewriteCond %{HTTP_HOST} ^blah04.com$ [OR]
RewriteCond %{HTTP_HOST} ^blah05.135$
RewriteRule (.*) http://www.whatIwantittoredirectto.com/$1 [R=301,L]

RewriteRule ^sitemap\.xml$ index.php?option=com_jmap&view=sitemap&format=xml [L]

## Begin - Rewrite rules to block out some common exploits.
# If you experience problems on your site then comment out the operations listed
# below by adding a # to the beginning of the line.
# This attempts to block the most common type of exploit `attempts` on Joomla!
#
# Block any script trying to base64_encode data within the URL.
RewriteCond %{QUERY_STRING} base64_encode[^(]*\([^)]*\) [OR]
# Block any script that includes a <script> tag in URL.
RewriteCond %{QUERY_STRING} (<|%3C)([^s]*s)+cript.*(>|%3E) [NC,OR]
# Block any script trying to set a PHP GLOBALS variable via URL.
RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9,A-Z]{0,2}) [OR]
# Block any script trying to modify a _REQUEST variable via URL.
RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\%[0-9,A-Z]{0,2})
# Return 403 Forbidden header and show the content of the root home page
RewriteRule .* index.php [F]
#
## End - Rewrite rules to block out some common exploits.

## Begin - Custom redirects
#
# If you need to redirect some pages, or set a canonical non-www to
# www redirect (or vice versa), place that code here. Ensure those
# redirects use the correct RewriteRule syntax and the [R=301,L] flags.
#
## End - Custom redirects

##
# Uncomment the following line if your webserver's URL
# is not directly related to physical file paths.
# Update Your Joomla! Directory (just / for root).
##

# RewriteBase /

## Begin - Joomla! core SEF Section.
#
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
#
# If the requested path and file is not /index.php and the request
# has not already been internally rewritten to the index.php script
RewriteCond %{REQUEST_URI} !^/index\.php
# and the requested path and file doesn't directly match a physical file
RewriteCond %{REQUEST_FILENAME} !-f
# and the requested path and file doesn't directly match a physical folder
RewriteCond %{REQUEST_FILENAME} !-d
# internally rewrite the request to the index.php script
RewriteRule .* index.php [L]
#
## End - Joomla! core SEF Section.

Thanks,

Dave

User avatar
darb
Joomla! Ace
Joomla! Ace
Posts: 1427
Joined: Thu Jul 06, 2006 12:57 pm
Location: Stockholm Sweden
Contact:

Re: SEO Redirects 5, 6, 7, 8 and 9 to home page

Post by darb » Wed Oct 31, 2018 6:21 pm

Hi do you have an url of your live site to look at?

have you tried to replace this htaccess file with Joomlas original htaccess file?

Code: Select all

##
# @package    Joomla
# @copyright  Copyright (C) 2005 - 2018 Open Source Matters. All rights reserved.
# @license    GNU General Public License version 2 or later; see LICENSE.txt
##

##
# READ THIS COMPLETELY IF YOU CHOOSE TO USE THIS FILE!
#
# The line 'Options +FollowSymLinks' may cause problems with some server configurations.
# It is required for the use of mod_rewrite, but it may have already been set by your 
# server administrator in a way that disallows changing it in this .htaccess file.
# If using it causes your site to produce an error, comment it out (add # to the 
# beginning of the line), reload your site in your browser and test your sef urls. If 
# they work, then it has been set by your server administrator and you do not need to 
# set it here.
##

## No directory listings
<IfModule autoindex>
  IndexIgnore *
</IfModule>

## Can be commented out if causes errors, see notes above.
Options +FollowSymlinks
Options -Indexes

## Mod_rewrite in use.

RewriteEngine On

## Begin - Rewrite rules to block out some common exploits.
# If you experience problems on your site then comment out the operations listed 
# below by adding a # to the beginning of the line.
# This attempts to block the most common type of exploit `attempts` on Joomla!
#
# Block any script trying to base64_encode data within the URL.
RewriteCond %{QUERY_STRING} base64_encode[^(]*\([^)]*\) [OR]
# Block any script that includes a <script> tag in URL.
RewriteCond %{QUERY_STRING} (<|%3C)([^s]*s)+cript.*(>|%3E) [NC,OR]
# Block any script trying to set a PHP GLOBALS variable via URL.
RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [OR]
# Block any script trying to modify a _REQUEST variable via URL.
RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\%[0-9A-Z]{0,2})
# Return 403 Forbidden header and show the content of the root home page
RewriteRule .* index.php [F]
#
## End - Rewrite rules to block out some common exploits.

## Begin - Custom redirects
#
# If you need to redirect some pages, or set a canonical non-www to
# www redirect (or vice versa), place that code here. Ensure those
# redirects use the correct RewriteRule syntax and the [R=301,L] flags.
#
## End - Custom redirects

##
# Uncomment the following line if your webserver's URL
# is not directly related to physical file paths.
# Update Your Joomla! Directory (just / for root).
##

# RewriteBase /

## Begin - Joomla! core SEF Section.
#
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
#
# If the requested path and file is not /index.php and the request
# has not already been internally rewritten to the index.php script
RewriteCond %{REQUEST_URI} !^/index\.php
# and the requested path and file doesn't directly match a physical file
RewriteCond %{REQUEST_FILENAME} !-f
# and the requested path and file doesn't directly match a physical folder
RewriteCond %{REQUEST_FILENAME} !-d
# internally rewrite the request to the index.php script
RewriteRule .* index.php [L]
#
## End - Joomla! core SEF Section.
Success in the long run Its not about the code its about the people and community that's make it!
Its not what you say its what you do that matters!

Darb - aka ssnobben

davegattis
Joomla! Fledgling
Joomla! Fledgling
Posts: 3
Joined: Tue Oct 30, 2018 12:53 pm

Re: SEO Redirects 5, 6, 7, 8 and 9 to home page

Post by davegattis » Wed Oct 31, 2018 7:27 pm

Thanks for the response. Yes, I went to the original distribution and substituted the .htaccess file. I had the same results. Very strange if I type any non-existent url that begins with 5 through 9, it redirects to index.php. 0 - 4 and it responds correctly with a 404 error.

Dave

User avatar
dmorell
Joomla! Apprentice
Joomla! Apprentice
Posts: 35
Joined: Wed Jul 16, 2014 9:56 pm

Re: SEO Redirects 5, 6, 7, 8 and 9 to home page

Post by dmorell » Thu Nov 01, 2018 2:47 am

When you enable SEF-URLs, URL rewriting, and rename htaccess.txt to .htaccess, the URL request processing looks a little like this.

First the .htaccess file passes all URLs that do not map to a physical file or directory to the Joomla index.php file.

Since you do not have a file on your server named 1,2,3 etc. the .htaccess file passes the request to index.php.

Second Joomla tries to figure out what component, view, and item is supposed to be served.

If your site uses Legacy URL routing (Global Config > Articles > Integration). Joomla will by default try to match the number in the URL to an article ID.

Joomla will then try to return that article. However, depending on the articles' existence, status, access the results will be different.

My recommendation is to create a redirect rule at the top of your .htaccess file and included the [L,R=301] last and redirect flags. This will create a 301 redirect prior to the URL being passed to Joomla.

davegattis
Joomla! Fledgling
Joomla! Fledgling
Posts: 3
Joined: Tue Oct 30, 2018 12:53 pm

Re: SEO Redirects 5, 6, 7, 8 and 9 to home page

Post by davegattis » Thu Nov 01, 2018 2:55 pm

Thanks for the insight. Rather than changing my .htaccess file, I changed the URL routing to modern, then enabled "Remove IDs from URLs". Hopefully Google won't smack me too hard.

Thanks,

Dave

User avatar
dmorell
Joomla! Apprentice
Joomla! Apprentice
Posts: 35
Joined: Wed Jul 16, 2014 9:56 pm

Re: SEO Redirects 5, 6, 7, 8 and 9 to home page

Post by dmorell » Fri Nov 02, 2018 2:32 pm

I would definitely recommend redirected all articles if you are dropping the ID from the URL. Otherwise, you can break internal linking as well as any external links pointing to your articles.

In this situation what I usually do is this...
  • Set Remove IDs from URLs to No
  • Use Screaming Frog to run a crawl of all articles.
  • Export the results of the crawl to Excel.
  • Write a formula using SUBSTITUTE() to remove IDs from the URLs.
  • I then use Excel (since It is already open with all my data) to create a SQL INSERT statement containing each URL. The SQL statement is written for the x_redirect_links table.
  • I run the SQL statement.
  • And last I set Remove IDs from URLs to Yes.
Doing this does take a little bit of technical know how. However, it is much faster than manually creating each redirect.

The redirects are vital since a 404 error will be returned if the ID is included in the URL.

I hope this helps.


Post Reply

Return to “Search Engine Optimization (Joomla! SEO) in Joomla! 3.x”