2

I'm looking for a simple trick

Let's say I have a Wordpress installation and image resources in this URL

http://example.com/wp-content/images/example.jpg

I would like to have the possibility of having another accessible URL (not rewritten) that points the same resources with a different route. For example

http://example.com/content/images/example.jpg

I don't need any changes in the Wordpress platform per se. Only being able to link this alternate URL without a redirect of any kind.

As the title suggests, being able to have dual URLs for the same resources.

I've tried some ideas with .htaccess but could never manage to make this work., so I'm not 100% if that is the way to go, or if there are better alternatives like Apache Virtualhosts or something.

  • 3
    Why "not rewritten"? Using mod_rewrite could do exactly what you want. – Stephen Ostermiller Dec 28 '19 at 0:48
  • 3
    Welcome to Webmasters! You do not say what OS or web server. On linux you can create a symlink named content that points to wp-content. If Apache, there may be other options. You mentioned .htaccess, what have you tried? Can you add an example or examples? Cheers!! – closetnoc Dec 28 '19 at 1:06
  • @StephenOstermiller, how exactly? This is what I've been trying unsucessfully – SirLouen Dec 28 '19 at 12:58
4

better alternatives like Apache Virtualhosts or something.

If you have access to the server-config, then you can use the Alias directive in the vHost to route all requests for /content/images to /wp-content/images.

For example:

Alias "/content/images/" "/wp-content/images"

Now, a request for /content/images/example.jpg would be sent to /wp-content/images/example.jpg.

However, if you are limited to using .htaccess then you will need to rewrite the URL using mod_rewrite.

2

Found the solution through .htaccess Never sure if it's the best, but it works:

RewriteRule ^([_0-9a-zA-Z-]+/)?content/(.*) /wp-content/$2 [QSA,L]
  • 3
    The way your question is written it sounds like you did not want to rewrite the URL (ie. "not rewritten") for some reason - which is why @StephenOstermiller was querying this in comments. Yet this is exactly what you are doing here? Note that what you have posted does more than what you stated in the question, as it will also rewrite /<something>/content/<anything>, whilst also preserving the query string - is this required? – MrWhite Dec 28 '19 at 16:55
  • @MrWhite. The real problem is this: When I use a mailer system within Wordpress (i.e Mailpoet), it uses by default all the wordpress routes wp-content for example. This is something that most spam systems seriously dislike. So I was looking for an option, to create "wp-content" or "wp-anything" emails but still, pointing to the wordpress routes. The importat thing here is that the HTML in the mail doesn't have the wp-content or wp-whatever, although the images from the origin are shown when the receipt gets the email. So I found out this was the best mechanism to accomplish this – SirLouen Dec 29 '19 at 16:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.