S
S
stikname2016-03-26 19:28:51
Apache HTTP Server
stikname, 2016-03-26 19:28:51

How to redirect all urls with? to the main page of the site (details in the description)?

Good evening, is there an attempt to redirect all urls with ? on the main page of the site, but there are nuances.
Here is an attempt to implement, by itself does not work:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{THE_REQUEST} \?
RewriteCond %{REQUEST_URI} !.css$
RewriteCond %{REQUEST_URI} !.js$
RewriteRule ^(.*)$ http://%{HTTP_HOST} [R=301,L]

Conditions under which we do not redirect:
1. if the file from the request really exists, for example asdf.php or asdf.xml?asdsad, etc. any extension
2. if the url is /asd.css or /asd.css?fasf - it doesn't matter if this file exists or not
3. if the url looks like /asd.js or /asd.js?fasf - it doesn't matter if this file exists or not
in all other cases redirect to the main page of the site. Here's how?

Answer the question

In order to leave comments, you need to log in

6 answer(s)
V
Viktor Taran, 2016-03-26
@shambler81

if the file exists, then this is the answer 200ok?
then you feel free to
check in nginx I would not recommend checking in .htaccess, without saying that it cannot be done without crutches.

E
Eugene K., 2016-08-01
@jin_x

RewriteCond %{QUERY_STRING} !^$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !\.(css|js)$ [NC]
RewriteRule ^ / [R=301,L]
In this case, the request ? will remain. If you do not need to save it, then add "?" to the slash in the last line: RewriteRule ^ /? [R=301,L]
Although, what's the point of checking for .css and .js if there is a REQUEST_FILENAME check?
Unless for requests non-existent files...

K
KorsaR-ZN, 2015-02-05
@KorsaR-ZN

And because you call the blink function in a loop (in general, you need it without brackets ), and in general such a construction will not work correctly.

for (var i = 0; i < li.length; i++) {
   setInterval(blink, 1000); 
}

To work correctly, tell me what you want to achieve? And why do you need a cycle here.
Just because the function is delayed, you will always have n = li.length - 1 Plus
, blink will be called more times than you intended :)

M
Mick Coder, 2015-02-05
@lbondodesc

The first argument of the setInterval() function is written incorrectly! How to

G
GreatRash, 2015-02-05
@GreatRash

It is more logical not to create a bunch of intervals, but to change the class of the parent, i.e. at ul. And depending on what class the parent has, the children will blink. This way you only need one interval, not a bunch per child.

D
Damir Rysaev, 2015-02-05
@freepad

Posted the code on jsfiddle.net

var ul = document.getElementById('blink'),
    li = ul.getElementsByTagName('li');

for(var i = 0; i < li.length; i++) {
  (function(el, i) {
        setInterval(function() {
            blink(el, i) 
        }, 1000);
    })(li, i);

}

function blink(el, i) {
  el[i].classList.toggle('cls');
}

1. Your setInterval() is written incorrectly . The blink() function is called immediately during the execution of the loop.
2. To understand the code, read about Closures and References in the JavaScript Garden guide

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question