on master help sign in
[mod] separate index and search routes

This makes it easier to separately handle search and index requests from a web server or from a reverse proxy. If a request to index contains a query, a permanent redirect HTTP response is returned. This should give some level of backwards compatibility for users that have set a searx instance in their browser's search bar.

commit8d71420b4511fdac63c39f33d93c7add1ea7716d authorMarc Abonce Seguin <marc-abonce@mailbox.org> dateMon 29 Jul 2019, 21:25 (7 years ago) parent45f58a4
17 files changed+70−42
searx/static/plugins/js/infinite_scroll.js+1−1 searx/templates/__common__/opensearch.xml+2−2 searx/templates/__common__/opensearch_response_rss.xml+1−1 searx/templates/courgette/results.html+6−6 searx/templates/courgette/search.html+2−2 searx/templates/legacy/infobox.html+1−1 searx/templates/legacy/results.html+6−6 searx/templates/legacy/search.html+1−1 searx/templates/oscar/results.html+8−8 searx/templates/oscar/search.html+1−1 searx/templates/oscar/search_full.html+1−1 searx/templates/pix-art/search.html+1−1 searx/templates/simple/infobox.html+1−1 searx/templates/simple/results.html+7−7 searx/templates/simple/search.html+1−1 searx/webapp.py+14−2 tests/unit/test_webapp.py+16
searx/static/plugins/js/infinite_scroll.js+1−1
@@ -9,7 +9,7 @@ function loadNextPage() {
99 $('#pagination').html('<div class="loading-spinner"></div>');
1010 $.ajax({
1111 type: "POST",
12− url: './',
12+ url: $('#search_form').prop('action'),
1313 data: formData,
1414 dataType: 'html',
1515 success: function(data) {
searx/templates/__common__/opensearch.xml+2−2
@@ -6,9 +6,9 @@
66 <Image>{{ urljoin(host, url_for('static', filename='img/favicon.png')) }}</Image>
77 <LongName>searx metasearch</LongName>
88 {% if opensearch_method == 'get' %}
9− <Url rel="results" type="text/html" method="get" template="{{ host }}?q={searchTerms}"/>
9+ <Url rel="results" type="text/html" method="get" template="{{ url_for('search', _external=True) }}?q={searchTerms}"/>
1010 {% else %}
11− <Url rel="results" type="text/html" method="post" template="{{ host }}">
11+ <Url rel="results" type="text/html" method="post" template="{{ url_for('search', _external=True) }}">
1212 <Param name="q" value="{searchTerms}" />
1313 </Url>
1414 {% endif %}
searx/templates/__common__/opensearch_response_rss.xml+1−1
@@ -4,7 +4,7 @@
44 xmlns:atom="http://www.w3.org/2005/Atom">
55 <channel>
66 <title>Searx search: {{ q|e }}</title>
7− <link>{{ base_url }}?q={{ q|e }}</link>
7+ <link>{{ url_for('search', _external=True) }}?q={{ q|e }}</link>
88 <description>Search results for "{{ q|e }}" - searx</description>
99 <opensearch:totalResults>{{ number_of_results }}</opensearch:totalResults>
1010 <opensearch:startIndex>1</opensearch:startIndex>
searx/templates/courgette/results.html+6−6
@@ -1,6 +1,6 @@
11{% extends "courgette/base.html" %}
22{% block title %}{{ q|e }} - {% endblock %}
3−{% block meta %}<link rel="alternate" type="application/rss+xml" title="Searx search: {{ q|e }}" href="{{ url_for('index') }}?q={{ q|urlencode }}&amp;format=rss&amp;{% for category in selected_categories %}category_{{ category }}=1&amp;{% endfor %}pageno={{ pageno }}">{% endblock %}
3+{% block meta %}<link rel="alternate" type="application/rss+xml" title="Searx search: {{ q|e }}" href="{{ url_for('search', _external=True) }}?q={{ q|urlencode }}&amp;format=rss&amp;{% for category in selected_categories %}category_{{ category }}=1&amp;{% endfor %}pageno={{ pageno }}">{% endblock %}
44{% block content %}
55<div class="right"><a href="{{ url_for('preferences') }}" id="preferences"><span>{{ _('preferences') }}</span></a></div>
66<div class="small search center">
@@ -10,12 +10,12 @@
1010 <div id="sidebar">
1111 <div id="search_url">
1212 {{ _('Search URL') }}:
13− <input type="text" value="{{ base_url }}?q={{ q|urlencode }}{% if selected_categories %}&amp;categories={{ selected_categories|join(",") | replace(' ','+') }}{% endif %}{% if pageno > 1 %}&amp;pageno={{ pageno }}{% endif %}" readonly />
13+ <input type="text" value="{{ url_for('search', _external=True) }}?q={{ q|urlencode }}{% if selected_categories %}&amp;categories={{ selected_categories|join(",") | replace(' ','+') }}{% endif %}{% if pageno > 1 %}&amp;pageno={{ pageno }}{% endif %}" readonly />
1414 </div>
1515 <div id="apis">
1616 {{ _('Download results') }}<br />
1717 {% for output_type in ('csv', 'json', 'rss') %}
18− <form method="{{ method or 'POST' }}" action="{{ url_for('index') }}">
18+ <form method="{{ method or 'POST' }}" action="{{ url_for('search') }}">
1919 <div class="left">
2020 <input type="hidden" name="q" value="{{ q|e }}" />
2121 <input type="hidden" name="format" value="{{ output_type }}" />
@@ -41,7 +41,7 @@
4141 {% if suggestions %}
4242 <div id="suggestions"><span>{{ _('Suggestions') }}</span>
4343 {% for suggestion in suggestions %}
44− <form method="{{ method or 'POST' }}" action="{{ url_for('index') }}">
44+ <form method="{{ method or 'POST' }}" action="{{ url_for('search') }}">
4545 <input type="hidden" name="q" value="{{ suggestion.url }}">
4646 <input type="submit" value="{{ suggestion.title }}" />
4747 </form>
@@ -60,7 +60,7 @@
6060 {% if paging %}
6161 <div id="pagination">
6262 {% if pageno > 1 %}
63− <form method="{{ method or 'POST' }}" action="{{ url_for('index') }}">
63+ <form method="{{ method or 'POST' }}" action="{{ url_for('search') }}">
6464 <div class="left">
6565 <input type="hidden" name="q" value="{{ q|e }}" />
6666 {% for category in selected_categories %}
@@ -71,7 +71,7 @@
7171 </div>
7272 </form>
7373 {% endif %}
74− <form method="{{ method or 'POST' }}" action="{{ url_for('index') }}">
74+ <form method="{{ method or 'POST' }}" action="{{ url_for('search') }}">
7575 <div class="left">
7676 {% for category in selected_categories %}
7777 <input type="hidden" name="category_{{ category }}" value="1"/>
searx/templates/courgette/search.html+2−2
@@ -1,7 +1,7 @@
1−<form method="{{ method or 'POST' }}" action="{{ url_for('index') }}" id="search_form">
1+<form method="{{ method or 'POST' }}" action="{{ url_for('search') }}" id="search_form">
22 <div id="search_wrapper">
33 <input type="text" autofocus placeholder="{{ _('Search for...') }}" id="q" class="q" name="q" tabindex="1" autocomplete="off" {% if q %}value="{{ q }}"{% endif %}/>
44 <input type="submit" value="search" id="search_submit" />
55 </div>
66 {% include 'courgette/categories.html' %}
7−</form>
7+</form>
searx/templates/legacy/infobox.html+1−1
@@ -36,7 +36,7 @@
3636 <div>
3737 <h3><bdi>{{ topic.name }}</bdi></h3>
3838 {% for suggestion in topic.suggestions %}
39− <form method="{{ method or 'POST' }}" action="{{ url_for('index') }}">
39+ <form method="{{ method or 'POST' }}" action="{{ url_for('search') }}">
4040 <input type="hidden" name="q" value="{{ suggestion }}">
4141 <input type="submit" value="{{ suggestion }}" />
4242 </form>
searx/templates/legacy/results.html+6−6
@@ -1,6 +1,6 @@
11{% extends "legacy/base.html" %}
22{% block title %}{{ q|e }} - {% endblock %}
3−{% block meta %}<link rel="alternate" type="application/rss+xml" title="Searx search: {{ q|e }}" href="{{ url_for('index') }}?q={{ q|urlencode }}&amp;format=rss&amp;{% for category in selected_categories %}category_{{ category }}=1&amp;{% endfor %}pageno={{ pageno }}">{% endblock %}
3+{% block meta %}<link rel="alternate" type="application/rss+xml" title="Searx search: {{ q|e }}" href="{{ url_for('search', _external=True) }}?q={{ q|urlencode }}&amp;format=rss&amp;{% for category in selected_categories %}category_{{ category }}=1&amp;{% endfor %}pageno={{ pageno }}">{% endblock %}
44{% block content %}
55<div class="preferences_container right"><a href="{{ url_for('preferences') }}" id="preferences"><span>preferences</span></a></div>
66<div class="small search center">
@@ -11,12 +11,12 @@
1111
1212 <div id="search_url">
1313 {{ _('Search URL') }}:
14− <input type="text" value="{{ base_url }}?q={{ q|urlencode }}{% if selected_categories %}&amp;categories={{ selected_categories|join(",") | replace(' ','+') }}{% endif %}{% if pageno > 1 %}&amp;pageno={{ pageno }}{% endif %}" readonly />
14+ <input type="text" value="{{ url_for('search', _external=True) }}?q={{ q|urlencode }}{% if selected_categories %}&amp;categories={{ selected_categories|join(",") | replace(' ','+') }}{% endif %}{% if pageno > 1 %}&amp;pageno={{ pageno }}{% endif %}" readonly />
1515 </div>
1616 <div id="apis">
1717 {{ _('Download results') }}
1818 {% for output_type in ('csv', 'json', 'rss') %}
19− <form method="{{ method or 'POST' }}" action="{{ url_for('index') }}">
19+ <form method="{{ method or 'POST' }}" action="{{ url_for('search') }}">
2020 <div class="left">
2121 <input type="hidden" name="q" value="{{ q|e }}" />
2222 <input type="hidden" name="format" value="{{ output_type }}" />
@@ -47,7 +47,7 @@
4747 <div id="suggestions"><span id="suggestions-title">{{ _('Suggestions') }} : </span>
4848 {% set first = true %}
4949 {% for suggestion in suggestions %}
50− {% if not first %} &bull; {% endif %}<form method="{{ method or 'POST' }}" action="{{ url_for('index') }}">
50+ {% if not first %} &bull; {% endif %}<form method="{{ method or 'POST' }}" action="{{ url_for('search') }}">
5151 <input type="hidden" name="q" value="{{ suggestion.url }}">
5252 <input type="submit" class="suggestion" value="{{ suggestion.title }}" />
5353 </form>
@@ -75,7 +75,7 @@
7575 {% if paging %}
7676 <div id="pagination">
7777 {% if pageno > 1 %}
78− <form method="{{ method or 'POST' }}" action="{{ url_for('index') }}">
78+ <form method="{{ method or 'POST' }}" action="{{ url_for('search') }}">
7979 <div class="{% if rtl %}right{% else %}left{% endif %}">
8080 <input type="hidden" name="q" value="{{ q|e }}" />
8181 {% for category in selected_categories %}
@@ -86,7 +86,7 @@
8686 </div>
8787 </form>
8888 {% endif %}
89− <form method="{{ method or 'POST' }}" action="{{ url_for('index') }}">
89+ <form method="{{ method or 'POST' }}" action="{{ url_for('search') }}">
9090 <div class="{% if rtl %}left{% else %}right{% endif %}">
9191 {% for category in selected_categories %}
9292 <input type="hidden" name="category_{{ category }}" value="1"/>
searx/templates/legacy/search.html+1−1
@@ -1,4 +1,4 @@
1−<form method="{{ method or 'POST' }}" action="{{ url_for('index') }}" id="search_form">
1+<form method="{{ method or 'POST' }}" action="{{ url_for('search') }}" id="search_form">
22 <div id="search_wrapper">
33 <input type="text" autofocus placeholder="{{ _('Search for...') }}" id="q" class="q" name="q" tabindex="1" autocomplete="off" size="100" {% if q %}value="{{ q }}"{% endif %}/>
44 <input type="submit" value="search" id="search_submit" />
searx/templates/oscar/results.html+8−8
@@ -7,7 +7,7 @@
77 <input type="hidden" name="language" value="{{ current_language }}" />{{- "" -}}
88 {% if timeout_limit %}<input type="hidden" name="timeout_limit" value="{{ timeout_limit|e }}" />{% endif -%}
99{%- endmacro %}
10−{%- macro search_url() %}{{ base_url }}?q={{ q|urlencode }}{% if selected_categories %}&amp;categories={{ selected_categories|join(",") | replace(' ','+') }}{% endif %}{% if pageno > 1 %}&amp;pageno={{ pageno }}{% endif %}{% if time_range %}&amp;time_range={{ time_range }}{% endif %}{% if current_language != 'all' %}&amp;language={{ current_language }}{% endif %}{% endmacro -%}
10+{%- macro search_url() %}{{ url_for('search', _external=True) }}?q={{ q|urlencode }}{% if selected_categories %}&amp;categories={{ selected_categories|join(",") | replace(' ','+') }}{% endif %}{% if pageno > 1 %}&amp;pageno={{ pageno }}{% endif %}{% if time_range %}&amp;time_range={{ time_range }}{% endif %}{% if current_language != 'all' %}&amp;language={{ current_language }}{% endif %}{% endmacro -%}
1111
1212{% block title %}{{ q|e }} - {% endblock %}
1313{% block meta %}{{" "}}<link rel="alternate" type="application/rss+xml" title="Searx search: {{ q|e }}" href="{{ search_url() }}&amp;format=rss">{% endblock %}
@@ -42,7 +42,7 @@
4242 </div>
4343 <div class="panel-body">
4444 {% for suggestion in suggestions %}
45− <form method="{{ method or 'POST' }}" action="{{ url_for('index') }}" role="navigation" class="form-inline pull-{% if rtl %}right{% else %}left{% endif %} suggestion_item">
45+ <form method="{{ method or 'POST' }}" action="{{ url_for('search') }}" role="navigation" class="form-inline pull-{% if rtl %}right{% else %}left{% endif %} suggestion_item">
4646 {% if current_language != 'all' %}
4747 <input type="hidden" name="language" value="{{ current_language }}">
4848 {% endif %}
@@ -71,7 +71,7 @@
7171 <label>{{ _('Download results') }}</label>
7272 <div class="clearfix"></div>
7373 {% for output_type in ('csv', 'json', 'rss') %}
74− <form method="{{ method or 'POST' }}" action="{{ url_for('index') }}" class="form-inline pull-{% if rtl %}right{% else %}left{% endif %} result_download">
74+ <form method="{{ method or 'POST' }}" action="{{ url_for('search') }}" class="form-inline pull-{% if rtl %}right{% else %}left{% endif %} result_download">
7575 {{- search_form_attrs(pageno) -}}
7676 <input type="hidden" name="format" value="{{ output_type }}">{{- "" -}}
7777 <button type="submit" class="btn btn-default">{{ output_type }}</button>{{- "" -}}
@@ -92,7 +92,7 @@
9292 <div class="clearfix">
9393 <span class="result_header text-muted form-inline pull-left suggestion_item">{{ _('Try searching for:') }}</span>
9494 {% for correction in corrections -%}
95− <form method="{{ method or 'POST' }}" action="{{ url_for('index') }}" role="navigation" class="form-inline pull-left suggestion_item">{{- "" -}}
95+ <form method="{{ method or 'POST' }}" action="{{ url_for('search') }}" role="navigation" class="form-inline pull-left suggestion_item">{{- "" -}}
9696 {% if current_language != 'all' %}
9797 <input type="hidden" name="language" value="{{ current_language }}">
9898 {% endif %}
@@ -140,13 +140,13 @@
140140 {% if rtl %}
141141 <div id="pagination">
142142 <div class="pull-left">{{- "" -}}
143− <form method="{{ method or 'POST' }}" action="{{ url_for('index') }}" class="pull-left">
143+ <form method="{{ method or 'POST' }}" action="{{ url_for('search') }}" class="pull-left">
144144 {{- search_form_attrs(pageno+1) -}}
145145 <button type="submit" class="btn btn-default"><span class="glyphicon glyphicon-backward"></span> {{ _('next page') }}</button>{{- "" -}}
146146 </form>{{- "" -}}
147147 </div>
148148 <div class="pull-right">{{- "" -}}
149− <form method="{{ method or 'POST' }}" action="{{ url_for('index') }}" class="pull-left">
149+ <form method="{{ method or 'POST' }}" action="{{ url_for('search') }}" class="pull-left">
150150 {{- search_form_attrs(pageno-1) -}}
151151 <button type="submit" class="btn btn-default" {% if pageno == 1 %}disabled{% endif %}><span class="glyphicon glyphicon-forward"></span> {{ _('previous page') }}</button>{{- "" -}}
152152 </form>{{- "" -}}
@@ -156,13 +156,13 @@
156156 {% else %}
157157 <div id="pagination">
158158 <div class="pull-left">{{- "" -}}
159− <form method="{{ method or 'POST' }}" action="{{ url_for('index') }}" class="pull-left">
159+ <form method="{{ method or 'POST' }}" action="{{ url_for('search') }}" class="pull-left">
160160 {{- search_form_attrs(pageno-1) -}}
161161 <button type="submit" class="btn btn-default" {% if pageno == 1 %}disabled{% endif %}><span class="glyphicon glyphicon-backward"></span> {{ _('previous page') }}</button>{{- "" -}}
162162 </form>{{- "" -}}
163163 </div>
164164 <div class="pull-right">{{- "" -}}
165− <form method="{{ method or 'POST' }}" action="{{ url_for('index') }}" class="pull-left">
165+ <form method="{{ method or 'POST' }}" action="{{ url_for('search') }}" class="pull-left">
166166 {{- search_form_attrs(pageno+1) -}}
167167 <button type="submit" class="btn btn-default"><span class="glyphicon glyphicon-forward"></span> {{ _('next page') }}</button>{{- "" -}}
168168 </form>{{- "" -}}
searx/templates/oscar/search.html+1−1
@@ -1,5 +1,5 @@
11{% from 'oscar/macros.html' import icon %}
2−<form method="{{ method or 'POST' }}" action="{{ url_for('index') }}" id="search_form" role="search">
2+<form method="{{ method or 'POST' }}" action="{{ url_for('search') }}" id="search_form" role="search">
33 <div class="row">
44 <div class="col-xs-12 col-md-8">
55 <div class="input-group search-margin">
searx/templates/oscar/search_full.html+1−1
@@ -1,6 +1,6 @@
11{% from 'oscar/macros.html' import icon %}
22
3−<form method="{{ method or 'POST' }}" action="{{ url_for('index') }}" id="search_form" role="search">
3+<form method="{{ method or 'POST' }}" action="{{ url_for('search') }}" id="search_form" role="search">
44 {% if rtl %}
55 <div class="input-group">
66 {% else %}
searx/templates/pix-art/search.html+1−1
@@ -1,4 +1,4 @@
1−<form method="{{ method or 'POST' }}" action="{{ url_for('index') }}" id="search_form">
1+<form method="{{ method or 'POST' }}" action="{{ url_for('search') }}" id="search_form">
22 <div id="search_wrapper">
33 <input type="text" autofocus placeholder="{{ _('Search for...') }}" id="q" class="q" name="q" tabindex="1" size="100" {% if q %}value="{{ q }}"{% endif %}/>
44 <input type="submit" value="" id="search_submit" />
searx/templates/simple/infobox.html+1−1
@@ -33,7 +33,7 @@
3333 <div>
3434 <h3><bdi>{{ topic.name }}</bdi></h3>
3535 {% for suggestion in topic.suggestions %}
36− <form method="{{ method or 'POST' }}" action="{{ url_for('index') }}">
36+ <form method="{{ method or 'POST' }}" action="{{ url_for('search') }}">
3737 <input type="hidden" name="q" value="{{ suggestion }}">
3838 <input type="hidden" name="time_range" value="{{ time_range }}">
3939 <input type="hidden" name="language" value="{{ current_language }}">
searx/templates/simple/results.html+7−7
@@ -1,7 +1,7 @@
11{% extends "simple/base.html" %}
22{% from 'simple/macros.html' import icon, icon_small %}
33{% block title %}{% if method == 'GET' %}{{- q|e -}} -{% endif %}{% endblock %}
4−{% block meta %}<link rel="alternate" type="application/rss+xml" title="Searx search: {{ q|e }}" href="{{ url_for('index') }}?q={{ q|urlencode }}&amp;categories={{ selected_categories|join(",") | replace(' ','+') }}&amp;pageno={{ pageno }}&amp;time_range={{ time_range }}&amp;language={{ current_language }}&amp;safesearch={{ safesearch }}&amp;format=rss">{% endblock %}
4+{% block meta %}<link rel="alternate" type="application/rss+xml" title="Searx search: {{ q|e }}" href="{{ url_for('search', _external=True) }}?q={{ q|urlencode }}&amp;categories={{ selected_categories|join(",") | replace(' ','+') }}&amp;pageno={{ pageno }}&amp;time_range={{ time_range }}&amp;language={{ current_language }}&amp;safesearch={{ safesearch }}&amp;format=rss">{% endblock %}
55{% block content %}
66<nav id="linkto_preferences"><a href="{{ url_for('preferences') }}">{{ icon('navicon-round') }}</a></nav>
77{% include 'simple/search.html' %}
@@ -55,7 +55,7 @@
5555 <h4 class="title">{{ _('Suggestions') }} : </h4>
5656 <div class="wrapper">
5757 {% for suggestion in suggestions %}
58− <form method="{{ method or 'POST' }}" action="{{ url_for('index') }}">
58+ <form method="{{ method or 'POST' }}" action="{{ url_for('search') }}">
5959 <input type="hidden" name="q" value="{{ suggestion.url }}">
6060 <input type="hidden" name="time_range" value="{{ time_range }}">
6161 <input type="hidden" name="language" value="{{ current_language }}">
@@ -71,13 +71,13 @@
7171
7272 <div id="search_url">
7373 <h4 class="title">{{ _('Search URL') }} :</h4>
74− <div class="selectable_url"><pre>{{ base_url }}?q={{ q|urlencode }}&amp;language={{ current_language }}&amp;time_range={{ time_range }}&amp;safesearch={{ safesearch }}{% if pageno > 1 %}&amp;pageno={{ pageno }}{% endif %}{% if selected_categories %}&amp;categories={{ selected_categories|join(",") | replace(' ','+') }}{% endif %}{% if timeout_limit %}&amp;timeout_limit={{ timeout_limit|urlencode }}{% endif %}</pre></div>
74+ <div class="selectable_url"><pre>{{ url_for('search', _external=True) }}?q={{ q|urlencode }}&amp;language={{ current_language }}&amp;time_range={{ time_range }}&amp;safesearch={{ safesearch }}{% if pageno > 1 %}&amp;pageno={{ pageno }}{% endif %}{% if selected_categories %}&amp;categories={{ selected_categories|join(",") | replace(' ','+') }}{% endif %}{% if timeout_limit %}&amp;timeout_limit={{ timeout_limit|urlencode }}{% endif %}</pre></div>
7575 </div>
7676 <div id="apis">
7777 <h4 class="title">{{ _('Download results') }}</h4>
7878 {% for output_type in ('csv', 'json', 'rss') %}
7979 <div class="left">
80− <form method="{{ method or 'POST' }}" action="{{ url_for('index') }}">
80+ <form method="{{ method or 'POST' }}" action="{{ url_for('search') }}">
8181 <input type="hidden" name="q" value="{{ q|e }}">
8282 {% for category in selected_categories %}
8383 <input type="hidden" name="category_{{ category }}" value="1">
@@ -100,7 +100,7 @@
100100 <h4>{{ _('Try searching for:') }}</h4>
101101 {% for correction in corrections %}
102102 <div class="left">
103− <form method="{{ method or 'POST' }}" action="{{ url_for('index') }}" role="navigation">
103+ <form method="{{ method or 'POST' }}" action="{{ url_for('search') }}" role="navigation">
104104 <input type="hidden" name="q" value="{{ correction.url }}">
105105 <input type="hidden" name="time_range" value="{{ time_range }}">
106106 <input type="hidden" name="language" value="{{ current_language }}">
@@ -133,7 +133,7 @@
133133 {% if paging %}
134134 <nav id="pagination">
135135 {% if pageno > 1 %}
136− <form method="{{ method or 'POST' }}" action="{{ url_for('index') }}">
136+ <form method="{{ method or 'POST' }}" action="{{ url_for('search') }}">
137137 <div class="{% if rtl %}right{% else %}left{% endif %}">
138138 <input type="hidden" name="q" value="{{ q|e }}" >
139139 {% for category in selected_categories %}
@@ -149,7 +149,7 @@
149149 </div>
150150 </form>
151151 {% endif %}
152− <form method="{{ method or 'POST' }}" action="{{ url_for('index') }}">
152+ <form method="{{ method or 'POST' }}" action="{{ url_for('search') }}">
153153 <div class="{% if rtl %}left{% else %}right{% endif %}">
154154 <input type="hidden" name="q" value="{{ q|e }}" >
155155 {% for category in selected_categories %}
searx/templates/simple/search.html+1−1
@@ -1,4 +1,4 @@
1−<form id="search" method="{{ method or 'POST' }}" action="{{ url_for('index') }}">
1+<form id="search" method="{{ method or 'POST' }}" action="{{ url_for('search') }}">
22 <div id="search_wrapper">
33 <div class="search_box">
44 <input id="q" autofocus name="q" type="text" placeholder="{{ _('Search for...') }}" tabindex="1" autocomplete="off" spellcheck="false" dir="auto" {% if q %}value="{{ q }}"{% endif %} >
searx/webapp.py+14−2
@@ -531,10 +531,22 @@ def index_error(output_format, error_message):
531531 )
532532
533533
534−@app.route('/search', methods=['GET', 'POST'])
535534@app.route('/', methods=['GET', 'POST'])
536535def index():
537− """Render index page.
536+ """Render index page."""
537+
538+ # redirect to search if there's a query in the request
539+ if request.form.get('q'):
540+ return redirect(url_for('search'), 308)
541+
542+ return render(
543+ 'index.html',
544+ )
545+
546+
547+@app.route('/search', methods=['GET', 'POST'])
548+def search():
549+ """Search query in q and return results.
538550
539551 Supported outputs: html, json, csv, rss.
540552 """
tests/unit/test_webapp.py+16
@@ -77,6 +77,11 @@ class ViewsTestCase(SearxTestCase):
7777
7878 def test_index_html(self):
7979 result = self.app.post('/', data={'q': 'test'})
80+ self.assertEqual(result.status_code, 308)
81+
82+ def test_search_html(self):
83+ result = self.app.post('/search', data={'q': 'test'})
84+
8085 self.assertIn(
8186 b'<h3 class="result_title"><img width="14" height="14" class="favicon" src="/static/themes/legacy/img/icons/icon_youtube.ico" alt="youtube" /><a href="http://second.test.xyz" rel="noreferrer">Second <span class="highlight">Test</span></a></h3>', # noqa
8287 result.data
@@ -88,7 +93,10 @@ class ViewsTestCase(SearxTestCase):
8893
8994 def test_index_json(self):
9095 result = self.app.post('/', data={'q': 'test', 'format': 'json'})
96+ self.assertEqual(result.status_code, 308)
9197
98+ def test_search_json(self):
99+ result = self.app.post('/search', data={'q': 'test', 'format': 'json'})
92100 result_dict = json.loads(result.data.decode())
93101
94102 self.assertEqual('test', result_dict['query'])
@@ -98,6 +106,10 @@ class ViewsTestCase(SearxTestCase):
98106
99107 def test_index_csv(self):
100108 result = self.app.post('/', data={'q': 'test', 'format': 'csv'})
109+ self.assertEqual(result.status_code, 308)
110+
111+ def test_search_csv(self):
112+ result = self.app.post('/search', data={'q': 'test', 'format': 'csv'})
101113
102114 self.assertEqual(
103115 b'title,url,content,host,engine,score,type\r\n'
@@ -108,6 +120,10 @@ class ViewsTestCase(SearxTestCase):
108120
109121 def test_index_rss(self):
110122 result = self.app.post('/', data={'q': 'test', 'format': 'rss'})
123+ self.assertEqual(result.status_code, 308)
124+
125+ def test_index_rss(self):
126+ result = self.app.post('/search', data={'q': 'test', 'format': 'rss'})
111127
112128 self.assertIn(
113129 b'<description>Search results for "test" - searx</description>',