.htaccess add query string to internal redirect

I am trying to create friendly masked rewrites in SEO.htaccess. The htaccess file works fine on localhost and my personal server, but doesn't seem to work on GoDaddys servers. I know that this is already a problem, but it works for a client who decided to use Godaddy as his host.

The problem is that rewriting seems to result in a redirect showing the rewritten query string in the browser URL bar, not the internal one. 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" remain as /images/ for the browser. I copied my short .htaccess below, the IP addresses changed 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] 

The hint of a potential note is that the display URL is /images/?query_string , NOT index.php?query_string , so it does not perform a full redirect, although external requests get a 301 response from the page request.

+6
source share
2 answers

I did not test anything, but just looked at this line ...

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

there is a syntax error. A hyphen after 9 should be escaped as technically, it is a range indicator. Most of the time you see that people put it at the end of the ] , and therefore it does not cause an error, and therefore most people think that they do not need to avoid it. You also do not need to hide slashes. Also, the use of a question mark makes the previous optional and does not know why you want it. So it should be:

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

I commented on some other rules so you can tell what is happening. You didn’t accept anything from the “old” one and rewrote it in the old directory. The following rule looks like you took everything where you found the word "/ old /", and you redirected it to yourself. You should not receive requests from 0.0.0.0 ever.

The hyphen in your last rule must go to the end of the brackets, so Apache does not look for a range.

Since we are dealing with .htaccess , we do not need previous slashes unless we use REQUEST_URI .

 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 RewriteCond %{REQUEST_FILENAME} !^index.php$ RewriteRule ^([A_Za-z0-9_-]+)/?$ index.php?loadPage=$1&mode=cms [QSA,L] 
0
source

Source: https://habr.com/ru/post/946461/


All Articles