include css and images when rewriting url to remote server - css

I have an apache http server and I want to redirect certain URL to an external(remote) site, so I set the following line in the httpd.conf file :
RewriteRule ^/datafeeds/customer_feed.jsp http://othersite.com/datafeeds/customer_feed.jsp [P]
the problem is that the page is returning without the css and images (all resources) because it's put as relative paths in the remote site .... I need all the css and images to appear normally as if I am opening the remote site from the browser, how can I do it?

I simply modified the rule to include all resources :
RewriteRule ^/datafeeds/(.+)$ http://othersite.com/datafeeds/$1 [P]

Related

How do I make the landing page of website appear on Google and not "Index of /"?

I have recently made my WordPress website live and want it to be visible on Google Search. However, when specifically searching for the website, Google does not show the site title or description entered in WordPress, but rather "Index of /" and a bit of server info as the page summary. Does anyone recognize this, and have some ideas on how to fix this?
Apache2 is running on an Ubuntu 18.04 server and everything is updated. I have both an index.html file and obviously an index.php file in the DocumentRoot directory specified in the Virtual Host file for apache. And have specified to use index.php first in the .htaccess file. I've also tried to add the URL of the page to Google Search Console and added a sitemap, but with no effect.
You can add these lines to .htaccess files (its located in root of the website). What it does its redirects any trafic you got on http://example.com to https://example.com Please check both locations in separate browsers (and again with removed cache) on how it works. SOmetimes apache can be configured so it wouldn't work out of the box (like it can require additional fixes to redirection code or to the additional blocks etc...)
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]

Redirecting Dynamic URLs with Multiple IDs using .htaccess (Wordpress)

I've just moved my site onto Wordpress, which means the URL structure has now changed. I'd like to use a Rewrite Rule in the .htaccess file to redirect dynamic URLs with multiple IDs in one single statement, but am not having any success. An example is:
OLD URL: example.co.uk/seasons/season.php?ID=1819
NEW URL: example.co.uk/seasons/1819
The statements I have tried in .htaccess are:
RedirectMatch 301 ^/seasons/season.php?ID=(.*).htm$ example.co.uk/seasons/$1
and
RewriteCond %{QUERY_STRING} ^?ID=1$
RewriteRule ^/seasons/season.php$ example.co.uk/seasons/? [R=301,L]
In neither case, the redirect fires. Is there something about a Wordpress .htaccess file that I'm not considering, or is the error with the statements I'm attempting. I'm using .htaccess 301 redirects for http to https and non-www to www without issue.
This is the fixed version of the approach you chose, to make an external redirection:
RewriteEngine on
RewriteCond %{QUERY_STRING} (?:^|&)ID=(\d+)(?:&|$)
RewriteRule ^/?seasons/season\.php$ https://example.co.uk/seasons/$1 [R=301,QSD]
Since both, the old and new URLs use the same host name you can simplify that:
RewriteEngine on
RewriteCond %{QUERY_STRING} (?:^|&)ID=(\d+)(?:&|$)
RewriteRule ^/?seasons/season\.php$ /seasons/$1 [R=301,QSD]
It is a good idea to start out with a 302 temporary redirection and only change that to a 301 permanent redirection later, once you are certain everything is correctly set up. That prevents caching issues while trying things out...
These rules will work likewise in the http servers host configuration or inside a dynamic configuration file (".htaccess" file). Obviously the rewriting module needs to be loaded inside the http server and enabled in the http host. In case you use a dynamic configuration file you need to take care that it's interpretation is enabled at all in the host configuration and that it is located in the host's DOCUMENT_ROOT folder.
And a general remark: you should always prefer to place such rules in the http servers host configuration instead of using dynamic configuration files (".htaccess"). Those dynamic configuration files add complexity, are often a cause of unexpected behavior, hard to debug and they really slow down the http server. They are only provided as a last option for situations where you do not have access to the real http servers host configuration (read: really cheap service providers) or for applications insisting on writing their own rules (which is an obvious security nightmare).

How to load wordpress by two URL

I need to wordpress from 2 url, my main wp already run in subdomain wp.domain.com but I can't access from domain.com/wp, I try some change in database and .httaccess file, but I can't run it with 2 url
I need can access both of them :
wp.domain.com
domain.com/wp
WordPress doesn't really support this setup. All posts have saved their URL in the database, if you display the site on the secondary URL all links will still point to the primary URL.
Additionally, displaying the same content on different domains (what this is) is usually penalized by search engines, which is something you usually want to avoid.
You can achieve this by configuring the Apache with mod_proxy and mod_proxy_html to proxy all requests on one domain to the other, rewriting the URLs in the process.
The Apache config for this looks like this:
ProxyPass /wp/ http://wp.domain.com/
ProxyPassReverse /wp/ http://wp.domain.com/
# to rewrite the URLs in the HTML
ProxyHTMLEnable On
ProxyHTMLExtended On
ProxyHTMLURLMap http://wp.domain.com https://domain.com/wp
But I'd recommend to stick to a single URL and configure Apache to redirect all requests on the secondary URL to the primary.
You can do that with a single line in a .htaccess:
RewriteRule ^(.*)$ http://wp.domain.com/$1 [R=301,L]

Not able to serve different robots.txt for CDN77

We are trying to implement CDN77 in wordpress with genesis framework and want to serve different robots.txt for CDN. We used the following code
RewriteEngine On
RewriteCond %{HTTP:VIA} !^.*\.rsc.cdn77.org$
RewriteRule ^robots\.txt$ robots_cdn77.txt [L]
Our website is https://example.com and we have added a CND CNAME for https://cdn.example.com
We are facing the issue that our main robots.txt is getting rewritten alongwith the robots.txt for CDN website. Both robots.txt become same for above links. Both https://example.com/robots.txt and https://cdn.example.com/robots.txt serve the same resource.
How would I change the rewriterule such that each link serves their own robots.txt instead?
I would suggest you to setup a rule in CDN configuration. Saying for example when https://example.com/robots.txt is requested before it contacts origin server it append something like /cdn/robots.txt once the response in received from origin server, serve it as /robots.txt it self. This is possible in akamai CDN. Not sure which one are you using.

.htaccess routing to subdirectory on server? performance/loading times

I wonder if it is possible to use an .htaccess file to rout my domain directly to a subdirectory on my server?
I bought a webhosting package from a regular webhoster where my domain.com is connected to my root directory of my server. I wonder if it is somehow possible to upload a .htaccess file to my root directory on my server that automatically routs domain.com (/index.php or /index.html) to domain.com/some-directory/ …
And of course I don't want the addressbar to update to domain.com/some-directory. I want my regular domain just to grab its files from the subdirectory instead of my root directory.
Just for better overview on my server.
So again, when calling mydomain.com it renders index.html (or .php) from my root directory on my server. However I want mydomain.com to render /subdirectory/index.html.
If this is possible, how can I do it? Is this bad in some way? Is there something I didn't think of, e.g. are there longer loading times or anything like that with that approach?
Thank you in advance.
Matt
update: or is this possible with a DNS setting on my web-admin-panel. I'm able to edit all DNS entries.
Try putting this in the htaccess file in your document root:
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/some-directory/
RewriteCond %{DOCUMENT_ROOT}/some-directory%{REQUEST_URI} -f [OR]
RewriteCond %{DOCUMENT_ROOT}/some-directory%{REQUEST_URI} -d
RewriteRule ^(.*)$ /some-directory/$1 [L]
Keep in mind if you try to access a directory and are missing a trailing slash, mod_dir will redirect the browser to the URL with the trailing slash and will expose "/some-directory/".
EDIT
Additionally, the 2 -f and -d conditions are to make sure the request is actually for a resource that exists. This isn't required, and if you have further htaccess files with rewrite rules, you probably don't want these. They ensure that if someone requests some bogus URL, the 404 message will be handled outside of the /some-directory/ directory. Otherwise the 404 message will say something along the lines of:
The requested URL /some-directory/blahblahblah was not found on this server.
Exposing that everything is being routed through /some-directory/.

Resources