Redirecting from example.com to www.example.com - apache

My site uses AJAX, and it seems like I have to include the full path when I use it to access a function. This is fine, as I can code it in. The problem is, I have hardcoded http://www.example.com... but if a user has gone to http://example.com (without the www) this gives an access problem and the AJAX won't execute.
I think the easiest way to resolve this would be to make sure that if a user goes to mysite.com, they are redirected to www.example.com.
I can find solutions online, but they all involve the htaccess file, which my server doesn't support - I have to use rewrite.script instead.
How can I do this using rewrite.script, or is there an alternative way to approach this?

Thanks for the suggestions - I was directed to this: http://seo-website-designer.com/Zeus-Server-301-Redirect-Generator which created the rewrite.script file I needed.

In .htaccess found in your root document:
Redirect http://example.com/ http://www.example.com/
If there is no support for .htaccess on your server, you may have to include meta tag redirect on the head of your page. or using javascript to check the URL source then redirect it.

Related

301 rdirect for custom URL

I have a custom made image gallery site that I converted to WordPress, this site have few thousands link like this
http://www.example.net/Gallery?cmd=viewCarGallery&carID=13&pgID=1
http://www.example.net/Gallery?cmd=viewCarGallery&carID=9&pgID=1
All link is now converted to wordpress and now I am facing problem redirect them, I tried to using like this
Redirect 301 /Gallery?cmd=viewCarGallery&carID=9&pgID=1 http://www.example.net/gallery/gallery_ID
Please help me how can I redirect this kind of URL.
A permanent 301 redirect in your .htaccess file lets search engines and others know that an old link has been replaced by a new one. It's the recommended method for directing traffic from an existing page.I added below codes in my .htaccess file.
Redirect 301 /oldfile.htm /newfile.htm
I think what you need is mod rewrite. Take a look here http://www.askapache.com/htaccess/modrewrite-tips-tricks.html
It looks like a similar question https://superuser.com/questions/155139/htaccess-301-redirect-with-regular-expressions

Most secure way to deny direct access to my folders in a server

I've been looking for the answer before asking you, but I haven't found the exact case I'm in.
My website has a lot of folders: /js, /css, /img... and I want to deny people accessing them. I think the best for me could be a redirection to my index, and I've made a first approach by typing this in my .htaccess:
Redirect 301 /js http://my.awesome.website/
But of course, every javascript I'm calling isn't loading because the redirection. My question is: there's a way to just redirect the access but keep calling my JS, imgs and so? or should I forget that solution and give a 403 Error?
Thank you in advance!
Perhaps the solution you search for is disabling directory listings ?
Blocking access to any of the directories is pointless if there is content in them the browser needs to run your site. Regardless of you using 301 or 403, 404, 500 or any other http status code: the browser will never ever have access to any file in that directory and you will have to live without javascripts, images, css, ...

Magento REST is not Found after http://{magentoHost}/api/

I am trying to access rest API for Guest User through
http://localhost/b_marketing/api/rest/products, but the page redirects to 404 page. I have checked retrive catalog products in ACL attributes RULES, REST - attributes and REST - ROLES, correctly. It also works correctly on my other project by using these all configurations.
There is one thing I need to mention here that my project works only when I use http://localhost/b_marketing/index.php , despite of setting up the htaccess rewrites and setting rewrite from admin panel. My apache rewrites are also set.
When I use http://localhost/b_marketing/api/?wsdl it works and some xml returns.
But I cannot use http://localhost/b_marketing/api/rest/products
The Response Header is always 404.
I also cannot access REST API using http://localhost/b_marketing/index.php/api/rest/products as well.
Make sure you have rewrite rule in .htaccess.
Go to magento root folder, in your case it is b_marketing
Open .htaccess file in any editor
Locate rewrite rule for api
If you don't have .htaccess file in place, you may consider to copy fron original
Magento packagem
If you run nginx:
.htaccess is not supported. Edit the nginx configuration and add the line:
location /api {
rewrite ^/api/rest /api.php?type=rest last;
}
I read that that line sometimes is already there however with the the word break instead of last. Thats wrong, change it to last.
Make sure to use -MultiViews. As the api.php and /api path have the same name (without extension), Apache might resolve api automatically to api.php and cause trouble.

Multiple Domains to Display Content from Landing Pages on Another Domain

We have created a bunch of landing pages on a Joomla CMS system, such that the URL for each landing page is www.domain.com/page1.html and www.domain.com/page2.html, and so on. Of course the page1.html isn't really an HTML file it is a dynamic CMS page, just rewritten with htaccess.
The goal is to have one of our other domains, something like www.uniquedomain1.com show the content of www.domain.com/page1.html. Or, another domain like www.uniquedomain2.html show the content of www.domain.com/page2.html.
This needs to be search engine friendly so we can't use URL masking. Also we can't use HTACCESS redirects as this actually changes the URL in the browser bar. Need to keep the www.uniquedomain1.com URL in the browser bar.
Tried Apache VirtualHost options without any luck. You can park in a directory but not from a URL.
Ended up parking the domains on one folder, and then creating a PHP script to detect the domain host and then use CURL to query the correct url and deliver content. This whole thing seems ridiculously over complicated, and of course CURL isn't the best option, but it is all we could get to work.
Any thoughts on how to do this, or a better solution?
You can use HTACCESS redirect rules to do it without performing a redirect.
Change the html file names to be the domain name of the desired domain like domain.tld and do something like this in an .htaccess file
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(?:www\.)?([a-z0-9\.-]+\.[a-z]+) [NC]
RewriteRule ^$ /%1.html [L]
A quick test of this worked for two of my test (sub)domains test.domain.tld and test2.domain.tld. Both properly redirected to files with the names test.domain.tld.html and test2.domain.tld.html without modifying the URL.
You could also just use your PHP wrapper script to grab the content of each of the miscellaneous html files and output them.
If you renamed all of your HTML files (as in my previous suggested answer) to be domain.tld.html you could do it fairly easily. Something might look like:
<?php
require($_SERVER['SERVER_NAME'] .'.html');

Apache RedirectMatch where destination URL contains Querystring?

I haven't found a solution to this, since all of my searching and research points to query string related issues when you're going from a file with a query string, over to another URL. In my case, I'm just looking to go from a regular folder/file, etc., to a URL with a query string.
I have a working .conf file which contains various rules for my site. I'd like to add in another one that looks like this:
RedirectMatch ^/webinar$ https://company.webex.com/company/onstage/g.php?t=a&d=123456
RedirectMatch ^/webinar/$ https://company.webex.com/company/onstage/g.php?t=a&d=123456
I've modified the URL to be more generic. This redirects properly when I type in www.company.com/webinar however, it's not going to the above URL. When I type in the above URL directly in a browser, it loads up fine.
The redirect is taking me to a generic Webex page. This could be an issue with the redirect, but I think it has to do with how RedirectMatch is handling the query string on this URL. I'm at a loss.
EDIT
There might be an issue in how I now have 3 redirects happening. The first is the /webinar, second is the above URL, and the third is that the above URL redirects to another page where quite frankly, webex may be handling iframes. Not 100% sure. So could the second redirect be borking the third, etc? I can provide more specifics as far as the webex URL's if required.
SOLUTION
The issue here is that Webex can't handle a double redirect which is what's happening. Instead, I had to leverage a PHP page with a header redirect in a separate folder off of the TLD. The above RedirectMatch syntax is correct, but for some reason, Webex borks it.