Not able to serve different robots.txt for CDN77 - wordpress

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.

Related

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 overwrite specific URLs to skip folder from path

I have WordPress installed in the folder /blog
I need to have a specific page that is part of that WordPress but which should not contain the segment /blog in the URL.
For example:
All my blog pages should be www.domain.com/blog/page-name
My Terms and Conditions page should be www.domain.com/terms-and-conditions
All the solutions I've found were affecting all my /blog/.. pages.
I just need a special condition for one specific page.
You need to internally pass the request to the Wordpress blog page.
This can be done through .htaccess and mod_proxy
your .htaccess file should contain
ProxyPass "/terms-and-conditions" "http://www.example.com/blog/terms-and-conditions"
ProxyPassReverse "/terms-and-conditions" "http://www.example.com/blog/terms-and-conditions"
Proxypass directive internally sent request as a proxy request.
Similar result can be expected from RewriteEngine using [P] flag like
RewriteEngine on
RewriteRule "terms-and-conditions" "http://www.example.com/blog/terms-and-conditions" [P]
Online example for the same is at .htaccess tester

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]

Accessing the data via controller and methods not working in CodeIgniter while integrating with Wordpress

I am integrating a Codeigniter project in the Wordpress root folder. While i am trying to access mysql data via controller and method like http://myapp/project/test it is displaying error as Nothing is Found
At the same time while i set project/test as default controller and the mysql data will appearing while accessing via url http://myapp/
So, Please tell me how can access data using controller and method.
Sounds like you haven't configured your .htaccess/CI installation to not include index.php in the URL.
Does http://my.app/index.php/project/test work? If so, just follow the directions here: http://ellislab.com/codeigniter/user-guide/general/urls.html
By default, the index.php file will be included in your URLs:
example.com/index.php/news/article/my_article
You can easily remove this file by using a .htaccess file with some simple rules. Here is an example of such a file, using the "negative" method in which everything is redirected except the specified items:
RewriteEngine on
RewriteCond $1 !^(index.php|images|robots.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
In the above example, any HTTP request other than those for index.php, images, and robots.txt is treated as a request for your index.php file.

Using a CDN to serve Images from the wordpress Shopp plugin

I am using a CDN with my shopp installation. I used super cache to do most of the setup for getting my content on the cdn. However, the images that are served by the database (product images) are not being pulled from the cdn. I did check that they exist on the cdn.
i know that you need to do something to the htaccess file and this is what i got so far
RewriteEngine On
RewriteBase /
RewriteRule ^.shop/images/(\d+)/?\??(.)$ http://cdn.example.com/shop/images/$1/?$2 [L,R=301]
but it doesn't seem to work. anyone know a solution?
The Query String (everything after ?) cannot be matched in RewriteRule directive.
RewriteEngine on
RewriteRule ^shop/images/(\d+)/ http://cdn.example.com/shop/images/$1/ [NC,QSA,R=301]
The above rule only matches URL, the query string (e.g. ?280,340,667194571) will be passed as is (no additional checks -- what for?). As long as URL is in this format shop/images/{some_digits_only}/ (e.g. example.com/shop/images/73/) it will issue Permanent redirect (301) and URL in browser will be changed to CDN URL (e.g. http://cdn.example.com/shop/images/73/?280,340,667194571).

Resources