1

I want to remove completely ALL slashes or backslashes at the end of the URL.

http://www.mp7.org/?site=69.com\\\\\\\\\\\\\

via .htaccess or PHP.

The following .htaccess rule do NOT work:

RewriteRule ^(.*)[/\]+$ $1 [L,R=301]

#### mod_rewrite in use
Options +FollowSymlinks
RewriteEngine On

Please provide alternate solution.

Melki
  • 579
  • 2
  • 5
  • 26
user6509
  • 27
  • 4
  • How is this URL generated? By you or externally? – Glitch Desire Apr 21 '13 at 15:11
  • This is a testing tool. ALL url's are generated externally. – user6509 Apr 21 '13 at 15:16
  • It doesn't work because the slashes are part of the query string. ["When the requested URI contains a query string, and the target URI does not, the default behavior of RewriteRule is to copy that query string to the target URI"](http://httpd.apache.org/docs/current/rewrite/flags.html#flag_qsd). See http://wiki.apache.org/httpd/RewriteQueryString for how to modify the query string using mod_rewrite. – quietmint Apr 21 '13 at 15:16

1 Answers1

0

You can do the following:

$string = substr($string, 0, strpos($string, "\\"));

If there will be no \ appear earlier


EDIT: The full code to test:

<?php
$string = "http://www.mp7.org/?site=69.com\\\\\\\\\\\\\\\\\\\\\\\\\\";
$string = substr($string, 0, strpos($string, "\\"));
echo($string);
?>
xlofev276
  • 36
  • 3
  • Well, the following code generates blank page: $string = substr($string, 0, strpos($string, "\")); ?> – user6509 Apr 21 '13 at 15:32
  • You had to change `$string` to the url. And if you want to see something you had to use `echo($string);` or `print $string;`. – xlofev276 Apr 21 '13 at 17:00
  • As I have stated the entire code returns blank page: – user6509 Apr 21 '13 at 17:12
  • I found the problem \\ = \ because \ is the escape character you have 13 \ in the url if you want to escape al this caracters you had to test it with 26 \ see the edit – xlofev276 Apr 21 '13 at 17:22
  • 13 \ gives a error because the last caracter escapes the ". Whats results that there will be missing a " – xlofev276 Apr 21 '13 at 17:24
  • [Click here to see the code working](http://ideone.com/RdatVR) – xlofev276 Apr 21 '13 at 17:26
  • I want ALL slashes or backslashes at the end of the URL to be removed, NO matter of the url or the number of the slashes/backslashes. If you have an idea how to process please insert the code here. Thanks – user6509 Apr 21 '13 at 18:12