首先,感谢您阅读:X
问题与说明:
我正在通过linux apache和iptables将http流量从端口80上的任何IP地址重定向到10.0.0.1:8080(django)。
When web user issue a request to this url (hello.gggstatic.com/generate_204******), I handle path to **generate_204**
url address, via this rule: re_path('.*generate_204.*', lambda r: HttpResponseRedirect('splash/')),
.
Buuuuut, users are seeing `//splash/` instead of `/splash/` in browser.
`http://10.0.0.1:8080//splash/` #django 404 not found
users must see:
`http://10.0.0.1:8080/splash/` #django can handle it and via "include('splash.urls')"
问题:如何在URL地址栏中管理/删除/处理“ //”!
日志:
[09/May/2020 13:43:36] "GET //generate_204 HTTP/1.1" 302 0
Not Found: //splash/
[09/May/2020 13:43:36] "GET //splash/ HTTP/1.1" 404 2328
我在Django项目中的urls.py文件:
urlpatterns = [
re_path('/static/', serve,{'document_root': settings.STATICFILES_DIRS}),
re_path('.*generate_204.*', lambda r: HttpResponseRedirect('splash/')),
path('', lambda r: HttpResponseRedirect('splash/')),
#path('admin/', admin.site.urls),
path('splash/', include('splash.urls')),
]
我在Django应用程序中的urls.py文件:
urlpatterns = [
re_path('^$', views.start, name='start'),
re_path('index/$', views.start, name='start'),
path('validation', views.validation, name='validation'),
path('bye', views.goodbye, name='goodbye'),
]
我的Apache配置:
<VirtualHost *:80>
ServerName hello.gggstatic.com
ServerAdmin webmaster@localhost
RewriteEngine On
RewriteCond %{HTTP_HOST} ^hello.gggstatic.com$
RewriteRule ^(.*)$ http://10.0.0.1:8080 [L,NC,R=302]
ErrorLog ${APACHE_LOG_DIR}/android_error.log
CustomLog ${APACHE_LOG_DIR}/android_access.log combined
</VirtualHost>