A
A
Anton Zolotarev2015-04-20 17:51:12
MySQL
Anton Zolotarev, 2015-04-20 17:51:12

How to make 2 conditions in Apache - Rewrite rule?

Colleagues, welcome!
I rarely run into mod_rewrite, I have a task to make a redirect when two conditions are met simultaneously:
1. The domain address is equal to domain.com
2. The page address is not equal to domain.com/f/s.php
I'm trying to use
RewriteCond %{SCRIPT_URI } !^ domain.com /f/s.php
RewriteCond %{HTTP_HOST} ^domain.com
RewriteRule ^(.*)$ newdomain.com/$1 [R=301,L]
But it redirects even if the page address matches domain.com/f/s .php
please tell me how best to do it.
Actually, even 2 questions:
1. How to write 2 conditions
2. How to write a page condition not equal to domain.com/f/s.php

Answer the question

In order to leave comments, you need to log in

4 answer(s)
D
Danil Sapegin, 2018-04-12
@Blitzzz

1. Check the indexes on the table. Do an explain select and see what indexes are being used. if the wrong one is used, then use FORCE INDEX
2. string fields if they are made varchar, it is better to change them to set / enum
3. For the test, remove parts of the query (for example, group) and see how the query accelerates. If it has accelerated significantly, then it is necessary to get rid of the grouping in the final version of the query and replace it, for example, with DISTINCT
4. If the table is large, then you need to think about data separation. If this is undesirable / impossible, then think in the direction of storing the necessary data on the number of employees in a field in the companies table, updating this data by cron once an hour, for example,
there are many acceleration options, in other words, this is a complex work and there is no single recipe here

G
gracer, 2015-04-20
@antonzol

RewriteCond %{HTTP_HOST} ^domain\.ru$
RewriteCond %{REQUEST_URI} !^/f/s\.php$
RewriteRule ^(.*)$ newdomain.com/$1 [R=301,L]

S
SagePtr, 2015-04-20
@SagePtr

If this page is to be believed: httpd.apache.org/docs/2.2/mod/mod_rewrite.html
then srcipt_uri also contains the protocol (http://)

A
Anton Zolotarev, 2015-04-21
@antonzol

added http:// before the new domain, so that it translates to the new domain and does not append the new one to the old one.

RewriteCond %{HTTP_HOST} ^domain\.ru$
RewriteCond %{REQUEST_URI} !^/f/s\.php$
RewriteRule ^(.*)$ newdomain.com/$1 [R=301,L]

Получается, что в $1 хранится домен и он много раз дописывается в строку.
В принципе устраивает и без переменной - редирект на главную.
Спасибо большое!

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question