Advanced 301 redirection for the whole site at the root of the site?

I am struggling with an age problem. I inherited a site with pretty good SEO and one glaring problem. The entire site is located in the / site / subdirectory. I decided that I need to upload the site to the root directory. So something like http://example.org/site/index.php will instead be redirected to /index.php (<-, which is considered a link, if it is unclear, I mean this is the root of the site / index.php.)

We use joomla for our backend, and at the moment there are hundreds of pages on the site. I struggled to get any of the redirects that I saw to do what I want them to do. In principle, any page that our visitors visited from an old link with / site / in should be redirected to the same link, but without a star.

I am open to loading a page with / site / and creating it as if it were root. As far as I understand, this can be done with some mod-rewrite changes ( http://kb.mediatemple.net/questions/85/Using+.htaccess+rewrite+rules#gs ?), But I have not been successful so far. I am launching a beta site that mimics the parent site in a subdomain that I have already moved from / site / to /, so I can test many .htaccess configurations.

Any help is appreciated ... thanks!

+5
source share
3 answers

To be sure: you want to http://example.org/site/foo/bar/baz.php go to http://example.org/foo/bar/baz.php , that is, remove (via redirection) the prefix / site, if one exists, but don’t touch the URL otherwise, right? If so, it depends on which server you are using:

  • If your server is Apache, you can use something like this in .htaccess :

     RedirectMatch 301 ^/site/(.*)$ http://example.com/$1 
  • If it is nginx, add this to the server {...} session of your site file (usually symbolically linked inside /etc/nginx/sites-enabled ):

     location ~ ^/site/(.*)$ { rewrite ^/site/(.*)$ /$1 permanent; } 

Here is a good explanation of how such pattern-based redirects can be configured on both servers.

+2
source

This seems to be the working answer I'll go with. In principle, this should be placed in the directory that you want to redirect, in my case, it is root / site /.


Rewriteengine on

RewriteCond% {http_host}! ^ www.beta.example.org $ [nc]

RewriteRule ^ (. *) $ Http://beta.example.org/ $ 1 [r = 301, nc, L]


I assume the first rule ignores www? I would like to get around this, but I don’t know exactly why it would have been created anyway. this will rewrite any URL that accesses this .htaccess file (inside your subdirectory) and direct you to the same URL without a list of subdirectories. This does not actually work with the index.php rewrite tool, but this is normal because it still reaches the correct page.

If anyone has a better option for me using Joomla, I would be happy to hear it. But, I already want it because it gives me great results.

+1
source

if your server is apache2 you can configure there

 <VirtualHost *:80> ServerName sitio.com ServerAlias www.sitio.com DocumentRoot /home/user/public_html/sitio/ ... </VirtualHost> 

You need permissions for this change.

0
source

Source: https://habr.com/ru/post/1205200/


All Articles