.htaccees redirect on long string - .htaccess

I wan't .htaccees to check it the url string is longer thnr 155 chars. If it is I want to redirect to an error page.
Her is a rule that does it (I think) for a 155 long query string, but I can't find a way to to this for a 155 and longer string. Also I am afraid that works only for url and not query string.
RewriteRule ^([a-zA-Z0-9]{155,})/?$ 404.php?u=$1 [QSA,L]

Why don't you try to preform the check in index file?
Here is an example:
$allowedL = 155;
$path = $SERVER['REQUEST_URI'];
if ( strlen($path) > $allowedL ) die();

Related

search and replace a string after a match

I have a file that contains :
String url = "https://url_address/v2.0/vpc/peerings?name=change_variable"
I try to change the string change_variable with something else like
String url = "https://url_adress/v2.0/vpc/peerings?name=florian-testpeering-5"
But when I use :
sed 's/"https:\/\/url_adress\/v2.0\/vpc\/peerings?name/"https:\/\/url_adress\/v2.0\/vpc\/peerings?name=florian-testpeering-5"/'g
I Obtain :
String url = "https://url_adress/v2.0/vpc/peerings?name=florian-testpeering-5"=change_url"
What I did wrong ?
Edit :
To be more precise, I need to change the change_variable inside with a $peering who I declare before in my script.
The fact that you have forward slashes in the url, means that is better to use another character for the sed separator and so:
sed 's#String url = "https://url_address/v2.0/vpc/peerings?name=change_variable"#String url = "https://url_address/v2.0/vpc/peerings?name=florian-testpeering-5"#g'
The normal / has been changed for #, allowing for easier reading and processing of the url.
Is this what you're trying to do?
awk 'index($0,"https://url_address/v2.0/vpc/peerings?name=change_variable") { sub(/change_variable/,"florian-testpeering-5") } 1' file
String url = "https://url_address/v2.0/vpc/peerings?name=florian-testpeering-5"
If I understand your edit, and you are saying you have your string in a variable at the beginning of your script, similar to:
var='String url = "https://url_address/v2.0/vpc/peerings?name=change_variable"'
and you need to change the contents of the string replacing from name=... to the end with a new value, you can simply use bash parameter expansion with substring replacement, e.g.
var="${var/name=*/name=florian-testpeering-5\"}"
Now the variable var will contain:
String url = "https://url_address/v2.0/vpc/peerings?name=florian-testpeering-5"
You can do the same thing if the string you want to replace with is also stored in another variable, such as repl="lorian-testpeering-5", in that case your substring replacement would be:
var="${var/name=*/name=${repl}\"}"
(same result in var)

htaccess redirect to new address removing double quotation and end characters

I would like to redirect the url in the form below(including double quotation and backslash!):
www.isfahancitycenter.com/%22form.php?form=showcalendar&id=168\%22 and its equivalent:
www.isfahancitycenter.com/"form.php?form=showcalendar&id=168\"
and also the urls in the form:
www.isfahancitycenter.com/%5C%22form.php?form=showcalendar&id=168%5C%22
(where 168 is the parameter that will change) to:
http://www.isfahancitycenter.com/form.php?form=showcalendar&id=168
Which means removing double quotation before form.php and any character at the end after the dynamic one 168
any help please?

Find a pattern in given string of URLs in Lua

In my Lua code I am receiving lot of URLs in form of string.
Example :
['http://www.abc.com/home/', 'http://www.abc.com/', https://www.xyz.com/v/123443/css/' , http://www.xyz.com/css/' ]
I want to fetch those URLs which are like :
https://www.xyz.com/v/123443/css/ where v is pre-defined string pattern and 123443 is random version generated to URL.
Please help me to fetch all URLs which are having that pattern into it like :
"/v/12332323/"
str = "https://www.xyz.com/v/123443/css/"
print(str:match("https?://www%.[^/]+(/v/%d+/)%w+"))
Output: /v/123443/
This pattern matches strings that starts with http or https, and then ://, the website name starting with www., a /, the pre-defined string v and "random" numbers, followed by / and other stuff.

Rewrite rule with redirect in php

I seem to have problem with an .htaccess rewriterule.
What I want to do is a dispatcher of this form:
[website]/[parameter1-text]/[parameter2-text]
I have in my .htaccess the following:
RewriteRule ^(.*)/(.*)$ dispatcher.php?s1=$1&s2=$2
So far so good. But s1 and s2 are some variables that need to be matched in a database (mysql) and return the true variables that feed the script view.php in the following format:
view.php?category=[s1]&subcategory=[s2]&objects=5
How can I redirect this properly using header("Location: /view.php[...]"); and having the url unchanged (for example: http://example.com/CARS/BLUE http://example.com/SLIPPERS/RED/ )
First of all fix some minor issues with your .htaccess:
RewriteRule ^([^/]+)/([^/]*)/?$ dispatcher.php?s1=$1&s2=$2 [L,QSA]
Now inside dispatcher.php do your Mysql stuff and fetch values of s1 and s2 from database. Once you're done and want to internally forward your request to: view.php?category=[s1]&subcategory=[s2]&objects=5 have this type of PHP code:
$_GET['category'] = $value-of-s1-from-DB;
$_REQUEST['category'] = $_GET['category'];
$_GET['subcategory'] = $value-of-s2-from-DB;
$_REQUEST['subcategory'] = $_GET['subcategory'];
$_GET['objects'] = '5';
$_REQUEST['objects'] = $_GET['objects'];
// now include view.php
// all your parameters are available in view.php in $_GET array
require_once("view.php");

How can I go back to showing the content of /index.php?

Here's part of my .htaccess file:
.htaccess:
RewriteRule ^([a-z0-9A-Z_-]+)$ /article/index.php?title=$1 [L]
But the problem is that when title is empty it doesn't show me the content of http://www.domain.com/index.php. I can't even link to http://www.domain.com/ anymore without throwing the error.
PHP: http://www.domain.com/article/index.php
<?php
if(!empty($_GET['title']))
{
$a = mysql_query("SELECT * FROM `articles` WHERE `title` = '".mysql_real_escape_string($_GET['title'])."'");
}
else
{
$a = mysql_query("SELECT * FROM `articles` WHERE `id` = '".mysql_real_escape_string($_GET['id'])."'");
}
$b = mysql_fetch_assoc($a) or mysql_error();
?>
You pretty much have 2 choices:
1. Use this rule: If home page is hit, then title parameter will be empty (so you have to handle this moment somehow -- adjust your PHP code accordingly).
RewriteRule ^([a-z0-9A-Z_-]*)$ /article/index.php?title=$1 [QSA,L]
2. Use specific rule for home page/website root hit (add it before your current rule):
RewriteRule ^$ /article/index.php?title=home [QSA,L]
The title=home means it's a hit for website root (you can change home to whatever you want).

Resources