i have to replace spaces in uri like :
/parma/vendita/villa%20schiera/via%20cremonese/
With a - char to have this:
/parma/vendita/villa-schiera/via-cremonese/10339
I really appreciate a suggestion to write isapi rewrite rule
Thanks :)
Try this rule:
RewriteBase /
RewriteRule ^(.*)\%20(.*)$ /$1-$2 [NC,LP]
Related
I am looking for regular expression which would match a pattern
/catalogue/name-of-the-product-p1-1-1.php
Or
/catalogue/name-of-the-product-p1.php
And redirect to:
/name-of-the-product
The code I tried:
RewriteRule ^/catalogue/([A-Za-z0-9-]+)-p(.+)\.php /$1 [R=301]
Any help would be appreciated.
Try
RewriteRule ^/?catalogue/([A-Za-z0-9-]+?)-p([0-9]+)([^.]*)\.php$ /$1 [R]
The regex pattern "^/?catalogue/([A-Za-z0-9-]+?)-p([0-9]+)([^.]*).php$" Can match
both Request uris /catalogue/name-of-the-product-p1-1-1.php Or /catalogue/name-of-the-product-p1.php it first matchs "catalogue" litearly, and then "([A-Za-z0-9-]+?)" matchs "name-of-the-product" and saves the value as $1 for reuse in Rewrite target.
Try this regex:
^/catalogue/([A-Za-z0-9-]+)-p[0-9]+(-[0-9]+)*\.php
Please help me with this problem. This is my htaccess rule :
RewriteCond %{REQUEST_METHOD} ^(GET)
RewriteRule ^ws/([^/]+)/([^/]+)/([A-Za-z]+)(&.+)?$ index.php?module=ws&wsType=$1&wsRessource=$2&wsAction=$3$4 [L,QSA]
This is what I want to match
ws/rest/user/get&criteria%5Befezf%5D=%2Ftot%2F&output=dump&compress=&session_id=cb932jrjakosubljl16loecbl1&api_key=a94a8fe5ccb19ba61c4c0873d391e987982fbbd3
The problem is around %2Ftot%2F. If I remove %2F (which is a slash / ), rewrite rule works
Add the [B] flag, i.e. [L,QSA,B], or add
AllowEncodedSlashes On
to Apache, or use %252F instead of %2F.
I searched in the web to find a valid solution for my problem, but nothing works.
Hopefully you guys can help me.
I want to Rewrite a URL on an Apache doing like that:
(1.) www.example.com/en/rainbow.html => www.example.com/index.php?site=rainbow&lang=en
or
(2.) www.example.com/rainbow.html =>www.example.com/index.php?site=rainbow&lang=
or
(3.) www.example.com//rainbow.html =>www.example.com/index.php?site=rainbow&lang=
To be honest, my understanding for regex isn't that good.
Tried:
RewriteEngine On
RewriteRule ^(.+)[/](.+).html|(.+).html$ index.php/?lang=$1&site=$2 [QSA]
Result: No Error, but "site" has only a param at (1.).
RewriteEngine On
RewriteRule ^(.*[/]){0,1}(.*).html$ index.php/?lang=$1&site=$2 [QSA]
Result: Works fine, but i.e. lang="en/", should be lang="en"
In which way I can improve it and let it work correct?!
Thanks a lot!!
Try this:
RewriteEngine On
RewriteRule (/en/)?([^/]+)\.html$ index.php/?site=$2lang=$1 [QSA]
No need to escape forward slashes in mod-rewrite, by the way. But you do need to escape the ., which, as you know, stands in as a wildcard in regular expressions.
I'm not an expert in url rewriting, but i like koalas:
RewriteRule /+(([^/]+)/)?([^/]+)\.html$ /index.php/?site=$3&lang=$2 [QSA]
I want to rewrite an url from example.php?id=123 to example-123-hello-world
(where "hello-world" is some fake text)
I tried this:
RewriteRule ^example-(.*)-(.*)$ /example.php?id=$1
it works only if there are no "-" in hello world:
example-123-helloworld
Any ideas how to do this? thanks a lot! :)
here's what you need to use:
RewriteEngine On
RewriteBase /
RewriteRule ^example\-([0-9]+)\-(.*)/?$ example.php?id=$1 [NC,QSA,L]
Try this:
RewriteRule ^example-(.*?)-(.*)$ /example.php?id=$1
I have to translate this: http://*myurl*/feedback.php?rcode=1307954819&lang=it
in
http://*myurl*/index.php?option=com_cake&module=lodgings&task=feedback&id=1307954819
Can someone help me ? :)
Edit:
I have to write it in .htaccess so I need rewrite rules.
# activate rewrite engine
RewriteEngine On
# mark / as a root
RewriteBase /
# rewrite feedback.php
RewriteCond %{QUERY_STRING} ^rcode=(\d+)
RewriteRule ^feedback.php$ index.php?option=com_cake&module=lodgings&task=feedback&id=%1 [L]
The rule above will rewrite /feedback.php?rcode=1307954819&lang=it into /index.php?option=com_cake&module=lodgings&task=feedback&id=1307954819 without changing URL in address bar of the browser.
If you need to change URL in address bar as well (to make a redirect) then change [L] into [R=301,L]
You don't need RegEx for this.
You can use str_replace.
$URL='http://myurl/feedback.php?rcode=1307954819&lang=it';
$newURL=str_replace(array('http://myurl/feedback.php','?rcode=','&lang=it'),array('http://myurl/index.php','?option=com_cake&module=lodgings&task=feedback&id=',''),$URL);
Without taking into acount option amd module params:
$url = 'http://*myurl*/feedback.php?rcode=1307954819&lang=it';
echo preg_replace('%^http://([^/]*)/([^.]*)\.php\?rcode=([0-9]*).*$%','http://$1/index.php?option=com_cake&module=lodgings&task=$2&id=$3',$url);
In .htaccess it should be:
RewriteRule ^/([^.]*)\.php\?rcode=([0-9]*).*$ /index.php?option=com_cake&module=lodgings&task=$1&id=$2
My example is in C# (not a php developer), but the regex pattern should work in both languages..
void Main()
{
string input = #"http://myurl/feedback.php?rcode=1307954819&lang=it";
Regex pattern = new Regex(".+?&?rcode=([^&]+)");
string output = pattern.Replace(input, #"http://myurl/index.php?option=com_cake&module=lodgings&task=feedback&id=$1");
Console.WriteLine(output);
}