1
如果reaquest參數未指定值,即「/?qwerty」(其中「qwerty」表示無效參數,沒有'='和任何值),我必須重定向到現場。我寫過.htaccess文件(網站與Joomla合作)。您可以看到以下片段:如何將參數未通過.htaccess賦值的URL重定向到404頁面?
RewriteCond %{REQUEST_METHOD} GET
RewriteCond %{QUERY_STRING} [a-zA-Z0-9_]=http:// [OR]
RewriteCond %{QUERY_STRING} [a-zA-Z0-9_]=(\.\.//?)+ [OR]
RewriteCond %{QUERY_STRING} [a-zA-Z0-9_]=/([a-z0-9_.]//?)+ [OR]
#Next string redirects all of requests with parameters
RewriteCond %{QUERY_STRING} [a-zA-Z0-9_] [NC]
RewriteRule ^(.*)$ index.php [R=404,L]
但現在網站無法處理任何帶參數的請求。我怎麼解決這個問題?
謝謝,但我的意思是它必須重定向任何參數名稱。您給了我一個主意,下面的代碼按照我的意願工作: 'RewriteCond%{QUERY_STRING}^[a-zA-Z0-9 _] + $ [OR] RewriteCond%{QUERY_STRING}^[a-zA-Z0-9_ ] + = $ [NC] RewriteRule^$ - [R = 404,L]' – andreytemn