I need an expression that would rewrite (actually 301 redirect) old url patterns ended with -0.htm, to new ones -1.htm
so if old url was /path/to/pagination/script-0.htm
new url must be /path/to/pagination/script-1.htm
This must work for any number of folder/subfolder structure.
And must work only for [-0.htm]. Only for urls that end with this pattern.
Any idea on how to accomplsh this?
My htaccess regex knowledge is limited to none.
You could try something like:
RewriteRule ^(.*?)\-0\.htm$ $1-1.htm [R=301,L]
But make sure it's one of the first rules, before the ones that might do a pass-through if a real file.
Related
I only modify the .htaccess with great care for the purposes of my online store.
Some time ago, I did a website migration from osCommerce to OpenCart. This resulted in orphaned osCommerce-style URLs with these two example formats:
http://www.londonpower.com/catalog/product_info.php?products_id=75
http://www.londonpower.com/catalog/product_info.php?cPath=15&products_id=75
Lots of websites in internet-land have links to my old-style URLs, and I have about 100 of them, so I would like to redirect them to new URLs with the following format:
http://www.londonpower.com/2-channel-guitar-preamp
If I understand correctly, the problem has two parts:
to eliminate the underscores, as they baffle the .htaccess engine;
to then perform a 301 redirect on the URL.
So far, I have been able to get the first underscore to change to a hyphen, with this Rewrite Rule:
RewriteRule ^([^_]*)_(.*)$ /$1-$2 [R=301,L]
...but no luck with the second underscore (the one that is part of the query string after the "?"). I am stuck there.
I would avoid using rewriting for this. Does the file catalog/product_info.php exist in the new store? If not, create it and add a simple redirection using a map of old IDs to new URLs. If so, do the same thing in a different file, like old-redirector.php then rewrite requests to it.
My web uses links which are dynamic set by code in htaccess (bellow):
RewriteRule ^(.*),(.*),([a-z0-9-_.]+),([a-z0-9-_.]+),([a-z0-9-_.]+)$ $4.php?n=$1&z=$2&t=$3&v=$5 [L,NC,NS,NE]
In effect links looks like this (example):
www.mypage.com/$1,$2,$3,$4,$5
I want to redirect dynamic links in htaccess from old to new one which will have a structure like this (without $5 parameter):
www.mypage.com/$4/$1-$2/$3
Redirection is necessarily especially for redirect old links availble in search engines to new one.
Thanks for a help.
I don't have an Apache instance to hand to test against just now but off the top of my head something like this should work:
RewriteRule ^(.*),(.*),([a-z0-9-_.]+),([a-z0-9-_.]+),([a-z0-9-_.]+)$ $4/$1-$2/$3 [L,R=301]
RewriteRule ^([a-z0-9-_.]+)/(.*)-(.*)/([a-z0-9-_.]+)$ $1.php?n=$2&z=$3&t=$4 [L,NC,NS,NE]
The first rewrite redirects your old URLs (1,2,3,4,5) to the new ones (4/1-2/3) using a 301 to tell search engines to drop the old URLs in favour of the new ones.
The second rewrite takes the new format and maps it to your actual script.
Note how the 5th param is dropped when transforming old to new.
I am designing a News Website using joomla 2.5
I want rewrite this url:
http://domain.com/categoryname/?format=feed&type=rss
to:
http://domain.com/rss/categoryname
Note: I'm using mode_rewrite .htaccess for joomla.
please help me quickly.
thanks to every body in this site.
Apache's mod_rewrite allows you to transform a url to a different url utilizing regex patterns.
The pattern applies to the path and allows you to do your in your example write a regex pattern like /rss/(.+) which will match anything beginning with /rss/ and has at least one character after. The parenthesis are called a capturing group and you can reference that in the second parameter in the RewriteRule directive.
The second part /$1/?format=feed&type=rss, references the first captured group in the pattern and places it in the new url.
Finally you want to signify that it is the last rule to be processed with an [L] flag.
This gives you a rule of:
RewriteEngine On
RewriteRule /rss/(.+) /$1/?format=feed&type=rss [L]
If you intend to pass query strings to this new url, you will need to add an additional flag QSA which will result in [L,QSA] in place of [L].
I am having issues with writing the proper redirect statement, and unfortunately can't rap my head around the syntax needed. Other questions have similar problems, but I can't figure out how to properly reuse the information in other posts.
I have a url: www.site.com/.../CORE_Testing_5010 this unique.
I need the page to redirect to www.site.com/core-phase
The ... could be multiple directories /a/b/c/d/CORE_Testing_5010 or just /a/CORE_Testing_5010
Right now, I have 310 redirects for most of the possible directory combinations, but that is inefficient.
Some guiedence and explanation would be helpful.
Try:
RedirectMatch 301 /CORE_Testing_5010$ /core-phase
The regex pattern ignored everything before the last /, so there can be anything in front of /CORE_Testing_5010.
If you have rewrite rules, and using mod_alias (the RedirectMatch) is causing conflicts, then you can stick with mod_rewrite:
RewriteRule /?CORE_Testing_5010$ /core-phase [L,R=301]
and it needs to be before any rules that do routing.
i am experiencing a very unique problem and i hope someone can help!
so we have recently created a new ecommerce website and we made it live and everything was working great but when we to implement our 301's from our old pages we were getting some wierd things
so the code below actually works
Redirect 301 /directory/ http://mysite.com/index.php?cat=1
this code does not
Redirect 301 /directory/sub_directory/ http://mysite.com/index.php?cat=2
the output when i try to do this redirection is "Invalid parameters specified!" on a blank webpage and in the address bar it has this
http://mysite.com/index.php?cat=1/sub_directory/
we were thinking that maybe the problem is because our old pages were dynamic but mod_rewrite was used to create more readable urls and we have also deleted all our old files because they were interfering with our new pages rendering
any help would be greatly appreciated!
thanks
That is strange, as redirect should only match the specific url listed, where as it looks like its behaving like rewriterule and partially matching the subdirectory url against the first rule..
try putting the more specific rule above the less specific, like so:
Redirect 301 /directory/sub_directory/ http://mysite.com/index.php?cat=2
Redirect 301 /directory/ http://mysite.com/index.php?cat=1
That way the more specific rule will be hit first, and the /directory/ only rule will only match if more specific matches above fail
alternatively, you could try RewriteRules:
RewriteRule ^directory/$ http://mysite.com/index.php?cat=1 [R=301,NC,L]
RewriteRule ^directory/sub_directory/$ http://mysite.com/index.php?cat=2 [R=301,NC,L]
the ^ and $ anchors should prevent any unwanted partial matching