[Resolved] .htaccess problem

Status
Not open for further replies.
#1
Who can tell me why these rules in my .htaccess rules don't work?
help plz
Apache config:
# if group_1 missed then redirect 410(Gone) without paramaters
RewriteCond %{QUERY_STRING} 'group_1=&'
RewriteRule ^tovary\.php - [R=410,L]

# replaces all '+'(whitespace) onto '%20' in query string
####### loop changing '+' onto '%20'
RewriteCond %{QUERY_STRING} (.*)\+(.*)
RewriteRule ^tovary\.php /tovary.php?%1\%20%2 [N,NE,E=PlusWasSubstitutedForHex:1]
####### 301 redirect to fix all substituting
RewriteCond %{ENV:REDIRECT_PlusWasSubstitutedForHex} 1
RewriteRule ^tovary\.php /tovary.php [NE,R=301,L]


On (Apache 2.2.17) is OK.
 
Last edited by a moderator:

NiteWave

Administrator
#2
let's test one by one.
for
# if group_1 missed then redirect 410(Gone) without paramaters
RewriteCond %{QUERY_STRING} 'group_1=&'
RewriteRule ^tovary\.php - [R=410,L]
enable rewrite log level 9, my test shows:
RewriteRule ^tovary\.php - [R=410,L]
Code:
2013-07-27 21:34:00.865 [INFO] [192.168.2.125:53459-0#Example] [REWRITE] Cond: Match 'a=1&group_1=&b=2' with pattern 'group_1=&', result: 1
2013-07-27 21:34:00.865 [INFO] [192.168.2.125:53459-0#Example] [REWRITE] No substition
2013-07-27 21:34:00.865 [INFO] [192.168.2.125:53459-0#Example] [REWRITE] Last Rule, stop!
if change above - to an existing file, it works:
RewriteRule ^tovary\.php /e.html [R=410,L]
Code:
2013-07-27 21:38:49.154 [INFO] [192.168.2.125:53493-0#Example] [REWRITE] Cond: Match 'a=1&group_1=&b=2' with pattern 'group_1=&', result: 1
2013-07-27 21:38:49.154 [INFO] [192.168.2.125:53493-0#Example] [REWRITE] Source URI: 'hello.php' => Result URI: '/e.html'
2013-07-27 21:38:49.154 [INFO] [192.168.2.125:53493-0#Example] [REWRITE] Last Rule, stop!
will show
410 Gone
The requested resource is no longer available at the server and no forwarding address is known.

in browser.
per rewrite log, it looks when "-" is used, rewrite flag R=xxx is ignored in litespeed's current implementation, this is a subtle difference.

in such kind of cases, change your rewrite rule is the quickest way to workaround it
 
#3
Good day, guys. Help with next rules, please.
Why does not work it?

Apache config:
RewriteCond %{QUERY_STRING} 'group_1=%CE%F0%E3%F2%E5%F5%ED%E8%EA%E0&group_2=%D3%ED%E8%F7%F2%EE%E6%E8%F2%E5%EB%E8+%E4%EE%EA%F3%EC%E5%ED%F2%EE%E2'
RewriteRule ^tovary\.php /shredder.php? [R=301,L] 2)

# replaces all '+'(whitespace) onto '%20' in query string
####### loop changing '+' onto '%20'
RewriteCond %{QUERY_STRING} (.*)\+(.*)
RewriteRule ^tovary\.php /_tovary.php?%1\%20%2 [N,NE]
RewriteCond %{QUERY_STRING} (.*)\+(.*)
RewriteRule ^_tovary\.php /_tovary.php?%1\%20%2 [N,NE]
####### 301 redirect to fix all substituting
RewriteCond %{QUERY_STRING} !(\+)
RewriteRule ^_tovary\.php /tovary.php [NE,R=301,L]
 
Last edited by a moderator:
#5
I'm added in httpd.conf into the section<logging>
<RewriteLogLevel>9</RewriteLogLevel>
and nothing .
The rules:

> ####### loop changing '+' onto '%20'
> RewriteCond %{QUERY_STRING} (.*)\+(.*)
> RewriteRule ^tovary\.php /_tovary.php?%1\%20%2 [N,NE]
> RewriteCond %{QUERY_STRING} (.*)\+(.*)
> RewriteRule ^_tovary\.php /_tovary.php?%1\%20%2 [N,NE]
> ####### 301 redirect to fix all substituting
> RewriteCond %{QUERY_STRING} !(\+)
> RewriteRule ^_tovary\.php /tovary.php [NE,R=301,L]
does not work and nothing to the log spelled.

For example:
Do 'tovary.php?pam+param' and not rewrite '+' into %20

P.S. Sorry for my english.
 

webizen

Well-Known Member
#6
I'm added in httpd.conf into the section<logging>

and nothing .
The rules:



does not work and nothing to the log spelled.

For example:
Do 'tovary.php?pam+param' and not rewrite '+' into %20

P.S. Sorry for my english.
Do not use "<RewriteLogLevel>9</RewriteLogLevel>" but "RewriteLogLevel 9" instead.
 
#9
So I did. No errors.
For rule:
RewriteCond %{QUERY_STRING} 'group_1=test&group_2=test'
RewriteRule ^tovary\.php /shredder.php? [R=301,L]
I'm doing:
site.com/tovary.php?group_1=%CE%F0%E3%F2%E5%F5%ED%E8%EA%E0&group_2=%D3%ED%E8%F7%F2%EE%E6%E8%F2%E5%EB%E8+%E4%EE%EA%F3%EC%E5%ED%F2%EE%E2
and it is not rewritten URL.
But. If I have rule
RewriteCond %{QUERY_STRING} 'group_1=test&group_2=test'
RewriteRule ^tovary\.php?$ /shredder.php? [R=301,L]
And doing:
site.com/tovary.php?group_1=test&group_2=test
It work.
Any ideas?
 
#11
you need to escape '+' in your matching pattern. iow, use '\+' instead of '+'.
I already tried to do. The fact that the "+" should be replaced by "20%"
To do this, have a rule, but it does not work.

RewriteCond %{QUERY_STRING} (.*)\+(.*)
RewriteRule ^tovary\.php /_tovary.php?%1\%20%2 [N,NE]
RewriteCond %{QUERY_STRING} (.*)\+(.*)
RewriteRule ^_tovary\.php /_tovary.php?%1\%20%2 [N,NE]
May be a bug in these rules?
 

webizen

Well-Known Member
#12
pls see rewrite log below. '+' is replaced with '%20'. So rewrite works as expected.

2013-07-29 17:18:03.693 [INFO] [xx.xx.xx.xxx:44000-0#APVH_www.example.com] [REWRITE] strip base: '/' from URI: '/tovary.php'
2013-07-29 17:18:03.693 [INFO] [xx.xx.xx.xxx:44000-0#APVH_www.example.com] [REWRITE] Rule: Match 'tovary.php' with pattern '^tovary\.php', result: 1
2013-07-29 17:18:03.693 [INFO] [xx.xx.xx.xxx:44000-0#APVH_www.example.com] [REWRITE] Cond: Match 'group_1=%CE%F0%E3%F2%E5%F5%ED%E8%EA%E0&group_2=%D3%ED%E8%F7%F2%EE%E6%E8%F2%E5%EB%E8+%E4%EE%EA%F3%EC%E5%ED%F2%EE%E2' with pattern '(.*)\+(.*)', result: 3
2013-07-29 17:18:03.693 [INFO] [xx.xx.xx.xxx:44000-0#APVH_www.example.com] [REWRITE] Source URI: 'tovary.php' => Result URI: '/_tovary.php?group_1=%CE%F0%E3%F2%E5%F5%ED%E8%EA%E0&group_2=%D3%ED%E8%F7%F2%EE%E6%E8%F2%E5%EB%E8%20%E4%EE%EA%F3%EC%E5%ED%F2%EE%E2'
2013-07-29 17:18:03.693 [INFO] [xx.xx.xx.xxx:44000-0#APVH_www.example.com] [REWRITE] replace current query string with 'group_1=%CE%F0%E3%F2%E5%F5%ED%E8%EA%E0&group_2=%D3%ED%E8%F7%F2%EE%E6%E8%F2%E5%EB%E8%20%E4%EE%EA%F3%EC%E5%ED%F2%EE%E2'
2013-07-29 17:18:03.693 [INFO] [xx.xx.xx.xxx:44000-0#APVH_www.example.com] [REWRITE] Next round, restart from the first rule
2013-07-29 17:18:03.693 [INFO] [xx.xx.xx.xxx:44000-0#APVH_www.example.com] [REWRITE] Rule: Match '/_tovary.php' with pattern '^tovary\.php', result: -1
2013-07-29 17:18:03.693 [INFO] [xx.xx.xx.xxx:44000-0#APVH_www.example.com] [REWRITE] Rule: Match '/_tovary.php' with pattern '^_tovary\.php', result: -1
 
Status
Not open for further replies.
Top