H
H
Hasan812018-04-20 10:29:18
htaccess
Hasan81, 2018-04-20 10:29:18

Error 404 htaccess with RewriteEngine on?

Hello!
there is .htaccess:
AddDefaultCharset UTF-8
Options -Indexes
RewriteEngine on
RewriteRule ^([A-Za-z0-9-/]+)$ /index.php?qline=$1 [L]
ErrorDocument 404 /index.php?base= error&addr=error
page output processing 404 on php is also implemented
BUT naturally if you write site.ru/test/test and there is no such page, then the server will still not swear, but will return /index.php?base=test&addr=test, and not /index.php?base=testerror&addr=error as you would like
Please tell me the error.
Can I rewrite one line of RewriteRule ^([A-Za-z0-9-/]+)$ /index.php?qline=$1 [L] into several:
RewriteRule ^(page)/(.*)$ /index. php?base=page&addr=$2[L]
RewriteRule ^(catalog)/(.*)$ /index.php?base=catalog&addr=$2 [L]
etc.
or something different?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Viktor Taran, 2018-04-20
@Hasan81

Based on the idiotic urls, this is clearly self-written, none of the 404 urls known to me with get parameters contains.
And therefore it is clearly self-written.
Tracking 404 blo would be more correct on the php side using your CNC
. I would also draw attention to the fact that you need to remove the index from the url and the get parameters in the ideal, leaving the normal CNC
without any.
However, I will answer your question.
It does not work for you for several reasons.
1. special characters need to be escaped,
ndex.php?baseguess where it is, moreover, this is such a common mistake that it was specially fixed in some versions of web servers
2. well, and most importantly, GET is not part of the RequestURI and naturally does not fall into the regular expression.
A different method is used to extract the get parameters.
.

# 301 --- http://www.mydefile.ru/company/?section=torgovlya&PAGEN_1=9 => http://www.mydefile.ru/about/
RewriteCond %{QUERY_STRING} (^|&)section=torgovlya($|&)
RewriteCond %{QUERY_STRING} (^|&)PAGEN_1=9($|&)
RewriteRule ^company/$ /about/? [L,R=301]

In the last rule, I showed how to remove the get parameter altogether
. You already figured out how to add it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question