Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.htaccess appending query string to internal redirect

I’m trying to create SEO friendly masked rewrites in .htaccess. The htaccess file works fine on localhost, and my personal server, but seems unfortunately does not work on GoDaddy’s servers. I'm aware that that's already an issue there, But working for a client who's set on using Godaddy as their host.

The issue is that the rewrite seems to be forcing a redirect showing the rewritten querystring in the browser URL bar instead of keeping it internal. eg.

Rule:

RewriteRule ^/?([a-zA-Z0-9-_/]*)$ /index.php?loadPage=$1&mode=cms [L,QSA]

Link: /images Redirecting to /images/?loadPage=images&mode=cms

this “should” stay as /images/ for the browser. I have copied my short .htaccess below, IPs modified for the development block

<Files .htaccess>
    deny from all
</Files>

Options -MultiViews +FollowSymlinks -Indexes

RewriteEngine On
RewriteBase /

# Stop Old redirection from block below
RewriteCond %{REQUEST_URI} "/old/"
RewriteRule (.*) $1 [L]

# Under construction Redirect
RewriteCond %{REMOTE_ADDR} !^0.0.0.0
RewriteCond %{REQUEST_URI} !^/?old/
RewriteRule ^/?(.*) “/old/$1″ [L,QSA]

#Admin utilities rewrite
RewriteRule ^/?admin/?(.*)$ /index.php?loadPage=$1&mode=backend [L,QSA]

#CMS/Frontend rewrites -- this one is failing
RewriteRule ^\/?([a-zA-Z0-9-_]+)\/?$ /index.php?loadPage=$1&mode=cms [QSA,L]

A hint of potential note is that the displayed url is /images/?query_string, NOT index.php?query_string, so it's not doing a full redirect, though external requests are receiving a 301 response from the page request.

like image 422
Refuting logic Avatar asked Jun 04 '13 01:06

Refuting logic


1 Answers

I haven't tested anything but simply looking at that line...

RewriteRule ^\/?([a-zA-Z0-9-_]+)\/?$ /index.php?loadPage=$1&mode=cms [QSA,L]

there is a syntax error. The hyphen after the 9 should be escaped as technically that is a range indicator. Most of the time you see people place it at the end before the ] and so it doesn't cause an error and so most people think they don't have to escape it. You also do not need to escape the forward slashes. Also using the question mark makes the previous optional, and don't know why you want that. So it should be like this:

RewriteRule ^([a-zA-Z0-9\-_]+)/?$ /index\.php?loadPage=$1&mode=cms [QSA,L]
like image 182
Anthony Hatzopoulos Avatar answered Nov 05 '22 13:11

Anthony Hatzopoulos