I am on abc.domainname.com
Now in any action
I want to redirect to a page domainname.com without subdomain.
How can I do this?
I tried like index_path(:subdomain => false).
If I hardcode like redirect_to("http://domainname.com"). Then it works.
I did in this way,
index_url(:subdomain => false)
And it works!
Related
I have site:
mysite.com/welcome
I wan't to remove the welcome-part of the url, but only IF the part is == welcome
for example:
mysite.com/welcome => mysite.com/
mysite.com/contact => mysite.com/contact
In any other case, the name after mysite.com stays the same.
I know it has something to do with the .htaccess-file on my server, but I can't figure out
how exactly I have to realize it. I assume I have to use regular expressions?
Thanks for any help
You can use this rule to remove welcome only:
RedirectMatch 301 ^/welcome$ /
Place this rule in your root .htaccess.
I want to redirect from:
http://www.domain.com/index.php?subdomain=subdomain
to
http://subdomain.domain.com/
using .htaccess
This can be done like so:
#Permanent Redirect
Redirect 301 / http://subdomain.domain.com/
Note: there is also a temporary redirect which would use the code 302
However, after reading your question more.. Looks like you want to use a header() Location change instead.
Here is how you can do that in PHP:
<?php
if(isset($_GET['subdomain']) && strlen($_GET['subdomain']) >= 1) {
$sub = $_GET['subdomain'];
$url = 'http://' . $sub . '.domain.com';
header("Location:$url");
}
?>
I think that might be more what you are after.
The .htaccess file controls everything inside its directory so if you set a redirect in the root of www.domain.com it will redirect ALL traffic.
On your .htaccess file type in
Redirect /example.html http://example.com/newdirectory/
Change example with your file/domain, you just
need to adjust it accordingly.
For further clarification,
Click here.
I've got urlManager rules:
...
'/<slug:(nasha-glavnaya-zagolovok)>' => 'page/page/show',
'/pages/<slug>' => 'page/page/show',
...
all fine.
When I enter to address
/nasha-glavnaya-zagolovok
it opens the page i need
But if I try to open page
/pages/nasha-glavnaya-zagolovok
it also opens the page I need
But content of pages are same.
How i can redirect (with 301 header) from route to pattern if any rule in urlManager mathced?
i cannot give you the complete answer, but you can work make it work like this...
you can use a rule that sends the request to an action which job is just to redirect using CController::redirect()
replace this
'/<slug:(nasha-glavnaya-zagolovok)>' => 'page/page/show',
'/pages/<slug>' => 'page/page/show',
with this
'/<slug:(nasha-glavnaya-zagolovok)>' => 'page/page/show',
'/pages/<slug>' => 'site/redirect',
and redirect the user to /$slug in the 'site/redirect' action
update: you can make it work by writing a new url rule which extends CBaseUrlRule, not sure if you care to take the time to do that if this is the only redirect you want to do though
I need to redirect help.mydomain.com/a-page to /pages/a-page without using Nginx or Apache redirects and only through Rails 3 routes.
The key here is the help subdomain determining that /pages/ should be dropped from the route although the view is under the /views/pages/
Any help is appreciated.
Try this:
match "/:page_name" => redirect("/pages/%{page_name}"), :constraints => { :subdomain => /help/ }
Google has indexed my Heroku app subdomain: myapp.heroku.com
Is it duplicate content?
How should I redirect myapp.heroku.com to mydomain.com?
According to Heroku docs for custom domains, you could do it like so:
class ApplicationController
before_filter :ensure_domain
APP_DOMAIN = 'myapp.mydomain.com'
def ensure_domain
if request.env['HTTP_HOST'] != APP_DOMAIN
# HTTP 301 is a "permanent" redirect
redirect_to "http://#{APP_DOMAIN}", :status => 301
end
end
end
I use this method and it works fine. Note that since the redirect returns a 301 http status (a permanent redirect) your site won't be penalized for duplicate content.
The 301 status is the only point missing in Markus' solution, but I think it is an important one if your concern is with SEO.
Edit: Something that's not on the docs and I forgot to mention - you should exclude the environments you don't want the redirect applied to. You could change the if statement to something like:
if request.env['HTTP_HOST'] != APP_DOMAIN && ENV["RAILS_ENV"] != 'development'
Use the Heroku add-on custom domains:
heroku addons:add custom_domains:basic
heroku domains:add www.myapp.com
heroku domains:add myapp.com
In addition, you have to take some configuration steps at the admin interface of your domain provider. You need a CNAME to proxy.heroku.com and three A-RECORDs to the Heroku IPs. You find this in the Heroku Docs.
Edit to respond to another answer below. You can redirect myapp.com to www.myapp.com in your routes.rb:
constraints(:host => /^communityguides.eu/) do
root :to => redirect("http://www.communityguides.eu")
match '/*path', :to => redirect {|params| "http://www.communityguides.eu/#{params[:path]}"}
end
I suggest using rack-canonical-host to redirect Heroku's subdomain to your custom domain.
rel canonical is one possibility
just put <link rel="canonical" href="http://mydomain.com"/>, <link rel="canonical" href="http://mydomain.com/page"/>, ... on your app pages.
see http://www.google.com/support/webmasters/bin/answer.py?answer=139394
google will treat the URL in the canonical element as the right ressource for that specific page.
The first answer goes part way to solve the problem but introduces a new problem.
If you add www.myapp.com and myapp.com you will then need to take care of redirecting one of these to the other inside your application - so if you choose www.myapp.com as your primary you want to check if the requested URL IS NOT www.myapp.com and redirect the request to www.myapp.com - this will then cover redirects requests coming to myapp.com and myapp.heroku.com correctly. There's an example by Heroku on their docs here.
Also, you need to get rid of the content that Google has already indexed on the Heroku domain. You'll need to use Google WebMaster tools to change the domain to www.myapp.com - it's a relatively simple process once you're logged into webmaster tools
first of all if you do not want your myapp.heroku.com to be indexed simply by adding robot meta tag in your header and give the value to "nofollow".
and for redirection just add another meta tag refresh:
<meta http-equiv="refresh" content="2;url=http://www.heroku.com/">
the content value is in seconds, the example above will direct visiotrs in 2 seconds to your main page.
hope it helps
Use the hide_heroku gem, it uses X-Robots-Tag HTTP headers to prevent search engines from indexing anything under *.herokuapp.com