[SOLVED] 404 and pretty URL problem

Have a question or a suggestion about a 3rd party addon module or plugin?
Let us know here.
Post Reply
Spinacia
New Member
New Member
Posts: 8
Joined: Sat Dec 22, 2012 3:54 pm

[SOLVED] 404 and pretty URL problem

Post by Spinacia »

Hi All,

The 404 "page not found" page on our CMSMS (ver 1.10.3) contains the following metadata which redirects the user to the sitemap page. The URL is relative because there are several parked domains on this server which users access interchangeably (.org, .net, .com, etc'):

Code: Select all

<meta http-equiv=refresh content="5;url=sitemap/">
<meta http-equiv=Page-Exit content="blendTrans(Duration=1.0)">
Pretty URLs are employed via HTACCESS rewrites. The HTACCESS file contains the following commands:

Code: Select all

##### General server settings ###############################
Options -Indexes
ServerSignature Off
Options +FollowSymLinks

##### Start the CMSMS rewrite rules ###############################
<IfModule mod_rewrite.c>

RewriteEngine on
RewriteBase /

# 301 Redirect all requests that do not contain a dot
# or trailing slash to include a trailing slash 
# but ignore POST requests.
RewriteCond %{REQUEST_URI} !/$
RewriteCond %{REQUEST_URI} !\.
RewriteCond %{REQUEST_METHOD} !POST$
RewriteRule ^(.*) %{REQUEST_URI}/ [R=301,L,NE]

# Rewrites URLs in the form of /parent/child/
# but only rewrites if the requested URL is not a file or directory.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/certgen/
RewriteRule ^(.+)$ index.php?page=$1 [QSA]

# Remove the .php extension from the URL, remove .php, and
# use THE_REQUEST to prevent infinite loops 
# due to DirectoryIndex redirects to .php files.
RewriteCond %{REQUEST_URI} !^/certgen(/.*)?$ [NC]
RewriteCond %{THE_REQUEST} ^GET\ /[^.]+\.php\ HTTP 
RewriteRule ^([^.]+)\.php$ $1/ [R=301] 

</IfModule>

##### Add WWW ###############################################
RewriteCond %{HTTP_HOST} ^company.com$ [NC]
RewriteRule ^(.*)$ http://www.company.com/$1 [R=301,L]

##### Remove trailing question mark #########################
RewriteCond %{THE_REQUEST} \?\ HTTP [NC] 
RewriteRule .? http://www.company.com%{REQUEST_URI}? [R=301,L]

##### Cache media files #####################################
<filesMatch "\\.(flv|gif|jpg|jpeg|png|ico|swf|js|css)$">
Header set Cache-Control "max-age=2592000, public"
</filesMatch>

##### Do not cache dynamic pages #############################
<filesMatch "\.(php|cgi|rss)$">
Header set Cache-Control "max-age=0, private, no-store, no-cache, must-revalidate"
</filesMatch>
The problem is that the resulting URL that is displayed in the web browser's address line after a 404 page and the redirect to the sitemap, contains the erroneous link that is coupled with the sitemap redirection.

For example, if a user attempts to load http://www.company.com/dadada/ (a non-existent URL) then the user will be correctly redirected to the 404 page and then to the sitemap page, but in their browser's address line the user will incorrectly see http://www.company.com/dadada/sitemap/ instead of the desired http://www.company.com/sitemap/ .

Any suggestions on how to fix this so that the desired pretty URL is showen?

Please help.

Thanks.
Last edited by Spinacia on Sat Dec 29, 2012 3:01 pm, edited 1 time in total.
User avatar
paulbaker
Dev Team Member
Dev Team Member
Posts: 1465
Joined: Sat Apr 18, 2009 10:09 pm
Contact:

Re: 404 and pretty URL problem

Post by paulbaker »

Try this? Add an extra /

Code: Select all

<meta http-equiv=refresh content="5;url=/sitemap/">
This extra / will return you to the root of the websites.
Spinacia
New Member
New Member
Posts: 8
Joined: Sat Dec 22, 2012 3:54 pm

Re: 404 and pretty URL problem

Post by Spinacia »

Hi Paul,

Yes, that extra / did solve the problem.

Thanks for your help and quick reply.
Post Reply

Return to “Modules/Add-Ons”