.htaccess htaccess /和字符重定向问题

oug3syen  于 2023-06-30  发布在  其他
关注(0)|答案(1)|浏览(138)

我有一个htaccess页面。我想重定向到404.php页面时/或一个字符被放置在我发送到详细页面的URL的末尾。我该怎么做?

RewriteEngine on
RewriteCond %{HTTP_HOST} ^localhost/ [NC]
RewriteRule ^(.*)$ http://localhost/$1 [L,R=301,NC]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php

RewriteRule ^([^/_.]+)$ detay.php?url=$1 [L,QSA]
RewriteRule ^sayfa/([^/_.]+)$ index.php?page=$1 [L,QSA]

#404 hata sayfası yönlendirme kodu
ErrorDocument 404 http://localhost/
<IfModule mod_security.c>
SecFilterEngine Off
SecFilterScanPOST On
</IfModule>

我在google上搜索了这个主题,我在其他论坛上开了一个主题,但是没有得到成功的答案。

dtcbnfnu

dtcbnfnu1#

RewriteEngine On
RewriteCond %{REQUEST_URI} /$ [OR]
RewriteCond %{REQUEST_URI} ^/[^/_.]{1}$
RewriteRule ^(.*)$ /404.php [L]
RewriteCond %{HTTP_HOST} ^localhost/ [NC]
RewriteRule ^(.*)$ http://localhost/$1 [L,R=301,NC]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
RewriteRule ^([^/_.]+)$ detay.php?url=$1 [L,QSA]
RewriteRule ^sayfa/([^/_.]+)$ index.php?page=$1 [L,QSA]
ErrorDocument 404 /404.php
<IfModule mod_security.c>
SecFilterEngine Off
SecFilterScanPOST On
</IfModule>

在将此添加到htaccess后,任何以斜杠或单个字符结尾的URL都会将其重定向到404.php页面
我不知道它是如何工作的,但它是一些遗留代码的一部分,我认为这将对你有帮助,因为它的工作与你提到的要求相同

评论后

RewriteEngine On

RewriteCond %{REQUEST_URI} /$ [OR]
RewriteCond %{REQUEST_URI} ^/[^/_.]{1}$
RewriteRule ^(.*)$ /404.php [L]

RewriteCond %{HTTP_HOST} ^localhost$ [NC]
RewriteRule ^(.*)$ http://localhost/$1 [L,R=301,NC]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php [L]
RewriteRule ^([^/_.]+)$ detay.php?url=$1 [L,QSA]

RewriteRule ^sayfa/([^/_.]+)$ index.php?page=$1 [L,QSA]

ErrorDocument 404 /404.php

<IfModule mod_security.c>
SecFilterEngine Off
SecFilterScanPOST On
</IfModule>

测试这个

相关问题