http error 503 notification page not rendering image - http

I tried a suggestion that used three headers in a 503.php page I created on the WordPress site's root directory:
header(“HTTP/1.1 503 Service Temporarily Unavailable”);
header(“Site Down for Maintenance, Status: 503 Service Temporarily Unavailable”);
header(“Retry-After: 86400”);
I used that time hoping I can get this back up in a day or two.
I also edited the .htaccess file on my hosting service site's root directory to except my own IP from the notice redirection when I type the domain so I can get into the admin area on the wp site.
I tried adding an echo line to display the company logo.
That logo is also in the site's root folder.
echo "<img src='/TU.jpg'>"
I want to add a line under the image with the company's phone number. I read that on a Unix server I can use \n to insert a line space.
Right now when a user types the domain name they are directed to this page. The three headers are rendered on the page but they include the word header, the parentheses, double quotes, and ending line semicolons in the code lines. They are all rendered on one wrapping line.
I would like to have them print without the extra code stuff on separate lines.
The logo also renders without spacing after the three header information lines, including the word echo and the quotation marks. I'd like to space them.
I tried this:
echo "<img src='/TU.jpg'>\n Company Phone: 754-701-0045";
but no line space is added.
With some help from my hosting service tech support I edited .htacess to add these lines at the bottom:
RewriteEngine on
RewriteCond %{REMOTE_ADDR} !^10\.10\.198\.52
RewriteCond %{REQUEST_URI} !/503.php$ [NC]
RewriteRule .* /503.php [R=302,L]
the ip exception would be mine - the one here is fake
I can't pretend I understand what it is doing. I'm a php dummy. I did the Crl-K and got the back ticks to insert the code between. I did, but the full file code seems to have broken something. I tried every way I could but still kept getting the warning about code not properly formatted...SORRY. I was only able to add those final lines as properly formatted code.
I tried inserting "\n" to separate the header lines but that didn't work either.

Related

How can I redirect one missing image to the correct path, but only that specific image?

I have a wordpress + woocommerce site with one particular issue. We have an icon image (png) that appears in the product and from time to time it removes the absolute URL of the image to a relative one using ../ and it creates an invalid URL. I need to catch all calls to that specific image, no matter what URL it is, of course, only the 404 ones, and redirect it to the right path.
For example, the right image is:
https://colmena.co.il/wp-content/uploads/2021/01/event-icon-xxs.png
And this is one of the wrong calls:
https://colmena.co.il/shop/eventos/wellness/wp-content/uploads/2021/01/event-icon-xxs.png
I need the second one to redirect to the first one, but I cannot use the full wrong URL because it changes based on the categories and subcategories (the /shop/eventos/wellness part).
I tried a couple of catch all examples found here and elsewhere trying to adapt them, but I just made it worse so I removed them all.
Any help is appreciated!
It is questionable if what you attempt really is a good idea. I personally would always prefer to fix the actual cause of the issue instead of trying to handle the symptom, as you suggest...
That said I assume the following is what you are actually looking for:
RewriteEngine on
RewriteRule ^/?shop/(?:[^/]+)/(?:[^/]+)/wp-content/uploads/2021/01/event-icon-xxs\.png$ /wp-content/uploads/2021/01/event-icon-xxs.png [L]
I think however that you can simplify that, since you most likely do not use a similar path for other locations:
RewriteEngine on
RewriteRule /?event-icon-xxs\.png$ /wp-content/uploads/2021/01/event-icon-xxs.png [L]

.htaccess change directory image

I have this blog and I've looking around the way to change my image path but nothing really works for me.
This is the URL where my image will display:
http://localhost/blog/article1/
inside is located <img src="images/logo.jpg" />
but with this URL the server searches for:
localhost/blog/article1/images/logo.jpg
And the real URL for my image is: localhost/blog/images/logo.jpg
I've tried with a lot of options but so far none have worked for me.
Note: the blog is made in WordPress, but some articles come with code from another migration, so I probably cannot change the whole articles.
What I need is to elevate subdirectory to localhost/blog/images
Well, you might get away with redirecting all calls that end with /back/back1.gif to that directory, so it wouldn't matter where the call came from. That does mean you should not wish to call this to some other subedirectory, but I imagine you don't.
something like this (guessing here, cann't test, so read up on the rwriting there :)
RewriteRule ^(.*)/images/$(.*) http://test.example.com/back/$2 [L,R=301]
basically you are rewriting everything that has '/images/' in it to that static adress, pasting whatever was after images after the new asdress (the $2 thingy) and then indicating that this is the last command to parse (to stop strange things in the htaccess) and that you want a 301 (permanently moved) code to be sent.

Too many redirects regex redirect

I am on Wordpress and right now using Yoast Seo Pro which has a redirection section including a Regular Expressions redirects section.
How do I redirect say /mycategory1/page/pagenumberhere/ to
/category/mycategory1/page/pagenumberhere/ ?
So I only need to make one redirect that handles all possible page numbers?
I have tried /mycategory1/page/([0-9]) to /category/mycategory1/page/$1
It looks like it redirects to /category/mycategory1/page/pagenumberhere/ but there is an err_too_many_redirects on the /category/mycategory1/page/pagenumberhere/ with this rule added so I have removed it again.
If you can help with code into the .htaccess instead perhaps I could try that.
Your rule already looks promising.
However, as #starkeen pointed out, the regular expression mycategory1/page/([0-9]) matches every request containing mycategory1/page/ with some trailing number. This is true of category/mycategory1/page/ as well, as it also contains "mycategory1/page".
If you want to match requests starting with mycategory1/page, you must anchor the regular expression at the beginning with ^, see Apache mod_rewrite Introduction - Regex vocabulary
RewriteRule ^mycategory1/page/([0-9]) /category/mycategory1/page/$1 [L]

Code needed for htaccess redirect in WordPress

I've been fixing a strange htaccess issue on my client's WP sites. I found a solution by putting the ReWrite code in the htaccess of each site and then adding a custom permalink code in permalinks and it seems to work EXCEPT for one section.
There are a total of 9 sites with this issue. All of them have a highlights plugin on the front page that's pulling story and images and displaying them on the home page and then a link that goes to the story full page. For my above permalink fix, out of the 9 sites, my fix works on 5 of them but on 4 of them in the highlights section, when you click a link I'm getting a 404.
The strange thing is, with my above fix, the highlight page still publishes, but not with my fix. For example, when you click the "fixed" link it should open as:
mysite.com/central/index.php/highlights/my-page
...but I get a 404. But all I have to do is delete the "index.php" in the above, and the page itself still works:
mysite.com/central/highlights/my-page
So what I now will do is write re-write code and put it in the root htaccess file so that when the page:
mysite.com/central/index.php/highlights/my-page
...is called it will re-write to:
mysite.com/central/highlights/my-page
...and that should fix this pesky issue. Here's the catch - I'm not good at writing code and I used my own hosting company's re-write generator to create a sample for me to see but I can't use it to generate what I need because it only generates for my domain. Since I don't know how to post code to this forum, below is a snap shot of it:
http://designerandpublisher.com/images/rewite-code.jpg
Is there a place where I can just copy and paste the URLs and it will generate the code so it looks like the above snap shot? Or is there some kind of tutorial of what / and \ and dollar signs and the periods and why they're there? I used to set up redirect code a lot simpler than this but it seems more complex now and i'm just hoping there's some kind of generator? Thanks for any assistance.
Adding the following rule should work:
RewriteRule ^central/index.php/(.*) /central/$1 [R=302]
it should turn mysite.com/central/index.php/highlights/my-page to mysite.com/central/highlights/my-page
(Change R=302 to R=301 when you are sure the redirect works)

Evaluating a external rewrite rule before internal wordpress rewrite rule

I am been plucking out my hairs since last few days trying to solve this problem:
I want to convert my urls from format
http://example.com/prodsearch/category/tag1-tag2-tag3-tag4
to
http://example.com/prodsearch/index.php?tag=tag1+tag2+tag3+tag4&cat=category
to start with I added following rules to my .htaccess
RewriteRule ^prodsearch/(.*)/(.*)-(.*)$ prodsearch/$1/$2+$3 [L]
RewriteCond %{REQUEST_URI} !^prodsearch/(.*?)/(.*)\-(.*)
RewriteRule ^prodsearch/(.*)/(.*)$ index.php?tag=$2&cat=$1 [R,QSA,L]
Here rule1 recursively replaces all '-' between tags by '+'
and rule2 does the actual rewrite once there are no more '-' left between tags (checked by RewriteCond)
These rules actually work, but the problem is they redirect (with url change) to new url pattern, I don't want an explicit redirection. On removing 'R' flag from last rule, the whole thing stops working and I start getting 404 page in my wordpress install.
Can some one explain why this is happening and how to do this without explicit redirection.
Also I tried including these rules into wordpress, hoping when called by wordpress rules may work without redirection. I used following add_rewrite_rule() calls:
add_rewrite_rule('prodsearch/(.*)/(.*)-(.*)$','price-list/$1/$2+$3','top');
add_rewrite_rule('prodsearch/(.*)/(.*)$','index.php?tag=$matches[2]&cat=$matches[1]','top');
Now wordpress detects my first rule as external rule and flushes it to .htaccess file, this screws my execution order, now first rule 2 gets evaluated first(being part of internal wordpress rewrite rule set) and rule 1 gets executed later, hence again 404 page.
Is it possible to tell wordpress not to consider my first rule as a external rule and not to flush it to .htaccess.
Or does anyone has any idea to make this kind of rewrite work? Thanks a lot.

Resources