Rewritecond htaccess remove all characters after slash (/)

亡梦爱人 提交于 2019-12-13 08:17:48

问题


I have the following htaccess

Options -Indexes +FollowSymLinks
RewriteEngine on
RewriteBase /
ErrorDocument 404 /404.php
RewriteEngine On    
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{THE_REQUEST} \s(.+?)/+[?\s]
RewriteRule ^(.+?)/$ /$1 [R=301,L]

That is removing slashes and the end of my urls. How can remove not only the slashes but all characters after the slash ? Or send a 404 maybe ?? Which one is better ? and how can it be done ?

For example www.mysite/index.php/index.php or anything else.


回答1:


If you just try to remove all characters after slash:

Options -Indexes +FollowSymLinks
ErrorDocument 404 /404.php
RewriteEngine on
RewriteBase /
RewriteRule ^([^/]+\.php)/.* $1 [R=301,L]

For 404 error change last line to:

RewriteRule ^[^/]+\.php/ - [R=404,L]


来源:https://stackoverflow.com/questions/27620311/rewritecond-htaccess-remove-all-characters-after-slash

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!