I moved a shop from xtc:modified to shopware.
The URLs look almost the same:
http://example.com/category/article::123.html
http://example.com/category/article
The only difference is ::123.html, 123 being different numbers.
Could you please provide me with the correct rewrite code to get rid of the :: and everything behind it?
I can't find the solution...
Thanks!
OK, so I did figure it out after a couple of more hours of trial and error:
RedirectMatch permanent (.+?)::.+$ https://www.example.com$1
Related
I'm having trouble with a regex to sort the following…
http://www.example.com/directory/listings/nostell-priory-2/
http://www.example.com/directory/listings/somerton-court-2/
http://www.example.com/directory/listings/shervage-court-2/
to look like the following…
http://www.example.com/directory/listings/nostell-priory/
http://www.example.com/directory/listings/somerton-court/
http://www.example.com/directory/listings/shervage-court/
I simply want to trim the -2 bit off the url but ONLY if the url contains the word listings.
Can anyone help?
Thanks,
James
Something like
RewriteRule ^directory/listings/(.*)-2/$ http://www.example.com/directory/listings/$1/ [R]
I really had troubles making a title. So if you have something better, please edit it.
Now to the question:
I'm trying to rewrite some URL's with mod_rewrite in my .htaccess file.
So, what I'm trying to do is to make 2 of the same queries, which of course won't work. Only for one of the rules. So I was thinking if there's some way to tell that if the first rule fails go to the next one? Or - if a rule fails keep looking for another?
Those are my rules which is identical except for the last parameter.
RewriteRule ^udforsk/([a-z-]+)/([0-9]+)$ index.php?page=udforsk&q=1&s=$1&val=$2
RewriteRule ^udforsk/([a-z-]+)/([0-9]+)$ index.php?page=udforsk&q=1&s=$1&p=$2
Correct me if I'm wrong but, if you are passing the arguments in via GET, then index.php should handle the error that would happen if it were missing a GET variable.
In index.php, treat $_GET["p"] like you would treat $_GET["val"], actually, why not use isset() and set p equal to val (if p isn't already set)
The rewrite won't check to see if the page you are calling in your rule is actually valid. It will just try to serve it up and then because you don't have [L] it will try to serve up the next one too.
What you should probably do is change your first URL to pass that $2 value as two different parameters
RewriteRule ^udforsk/([a-z-]+)/([0-9]+)$ index.php?page=udforsk&q=1&s=$1&val=$2
RewriteRule ^udforsk/([a-z-]+)/([0-9]+)$ index.php?page=udforsk&q=1&s=$1&p=$2
should be
RewriteRule ^udforsk/([a-z-]+)/([0-9]+)$ index.php?page=udforsk&q=1&s=$1&val=$2&p=$2
Then let your index.php do the work of picking which parm to use "val" or "p" based on logic in the php script.
For sure in your php code use "isset" to test for the variable.
$value = (isset($_REQUEST["val"]) ? $_REQUEST["val"] : (isset($_REQUEST["p"]) ? $_REQUEST["p"] : "error"));
$value will hold the contents of "val" or "p" or the word "error" if neither of the others are set.
I've written this short piece of php code that requires 2 variables name and id, now the code itself works as intended and is not my problem, the problem is that I want to shorten the link to this file from 'http://www.mypage.org/folder/index.php?name=name&id=0' to 'http://www.mypage.org/folder/name;0', like so:
RewriteRule ^([a-zA-Z0-9]+);(.*)$ index.php?name=$1&id=$2
But if someone enters a link like 'http://www.mypage.org/folder/name' with out the ';' separator they get a 404 page.
Is there a way to write a sort of if statement that also checks for links with out the ';'?
The php page can handle a missing id by defaulting to '0' as well as a missing name.
Thanks in advance!
Make ;0 part or URL optional:
RewriteRule ^([a-zA-Z0-9]+)(?:;(.*))?$ index.php?name=$1&id=$2
or like this (if the above does not work in Apache)
RewriteRule ^([a-zA-Z0-9]+)(;(.*))?$ index.php?name=$1&id=$3
I am trying to URL Rewrite to the following URL
Http://***.com/index.php?p=forum&mod=view_posts&page=$3&name=$2&id=$1
Http://***.com/forum/{id}-{name}/{page}
Http://***.com/forum/1-Hello-World/1
I have tryed the following code and have had no joy
RewriteRule ^forum/([^-]+)-([^&]+)/([^-]+)$ index.php?p=forum&mod=view_posts&page=$3&orderby=$2&id=$1
Thanks
That regex isn't very good: you see, the "([^&]+)" says: "one or more characters, up until the first ampersand", while you have no ampersands in the subject. Also, the "([^-]+)$" says "one or more characters before a hyphen", while you don't intend to end the subject with a hyphen.
Try this one:
^forum/([^-]+)-([^/]+)/(.+)$
But note that this actually captures any characters in the id and page positions, so you might be better off with
^forum/([0-9]+)-([^/]+)/([0-9]+)$
as that allows only numbers in those positions.
Also, you probably meant "index.php?p=forum&mod=view_posts&page=$3&name=$2&id=$1" instead of "index.php?p=forum&mod=view_posts&page=$3&orderby=$2&id=$1"
I am using htaccess. I try to pass a value in url like 'C++'.
like "http://domain.com/Details/c++/detail.html"
I am retrieving the value in htaccess like
RewriteRule ^Details/([a-zA-Z_0-9_.,'&/-]+)/(([a-zA-Z_0-9_.,'&/-]+).html)$ index.php?page=$2&id=$1
But it returns only 'c'. Symbol '+' not accepted. I need the the value 'c++'.
Is there any solution?
Try Url encoding the + character.
"http://domain.com/Details/c%25%25/detail.html"
Is it possible to escape it, like http://domain.com/Details/c%25%25/detail.html. (I'm only guessing)
http://domain.com/Details/c%2B%2B/detail.html
A small consolation is: you are not alone. Since this problem is by design in URIs, eben big sites like Google have their problems with it:
http://www.google.com/search?q=c++
This does a search for just “c”.
Try it with the B flag:
RewriteRule ^Details/([a-zA-Z0-9_.,'&/-]+)/([a-zA-Z0-9_.,'&/-]+\.html)$ index.php?page=$2&id=$1 [B]