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.
Related
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]
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)
In WordPress I'm using the Events Manager plugin, which uses the /events/subpage path in the URL.
I need to tweak things slightly so that /courses/subpage rewrites to /events/subpage i.e. the content of /events/subpage is shown when going to /courses/subpage. The URL should stay as /courses.
I thought this rule would do it:
RewriteRule ^courses/?(.*)$ /events/$1 [L]
But the URL changes from /courses to /events so it looks like my rule isn't quite right.
EDIT
Strangely I can put anything in place of /courses and it resolves to /events anyway. Confused!
Think I’ve cracked it.
I uninstalled the rewrite plugin and replaced it with Rewrite Rules Inspector. Then I added the following to functions.php
add_rewrite_rule(‘^course/([^/]*)/?’, ‘index.php?event=$matches[1]‘, ‘top’); // single event
In Rewrite Rules Inspector is said the rule was missing. I flushed the rules using the plugin and everything appears to be working now. It looks like the original rewrite plugin wasn’t flushing the rules properly.
I have a Wordpress based website that I scrap using wget.
I have articles under the form
http://mydomain.com/2011/01/
once scraped becomes
http://mydomain.com/2011/01.html
I found out that when I enter
http://mydomain.com/2011/01/
in the navigator, URL gets changed to
http://mydomain.com/2011/01
which is why, I think, it is considered as a file when I call wget.
I would be very grateful if someone has some clue on how to address this.
I finally managed to get to the result I wanted, in this way:
changing my permalink structure from
/%year%/%monthnum%/%postname%.html
to
/%year%/%monthnum%/%postname%/
I'm loading a background-image with a url like this:
background-image: url(../../images/folder/imageName.png);
For certain pages, this works fine, but on others, it only works if I put a slash at the front like this:
background-image: url(/../../images/folder/imageName.png);
Its bizarre to me that this would work sometimes and not others. Also, my gut feeling is telling me that starting these urls with a slash is just plain wrong.
Does anyone have any insight on this?
Starting urls without a protocol (http://, etc) means it is relative to the current document. If the different pages are in different folders then the file that relative URL points to will change, which is probably your problem.
Starting a URL with a slash makes it relative to the entire domain/subdomain the page is on. I consider this a good practice so would encourage you to use it.
In your example however you are following it with ../../, which are "directory above" hints, which are ignored because you are already at the base of the domain.
I think I figured it out. My stylesheet is at an address like this:
http://localhost/rootDirectory//pageName/stylesheet.css
Note the two slashes between rootDirectory and pageName. It seems that when my images used the .. to go back directories, it treated the empty space between those slashes as a directory itself (while loading the stylesheet did not treat it as its own directory and had no affect on the path loaded).
So this is why for some stylesheets, ../../ seemd to work, and for others it didn't (as a matter of fact, ../../../ worked instead)