.htaccess rewrite base URL up one directory level - drupal

I have an established Drupal installation at example.com/drupal - and now I need to move the installation up one level to the domain root.
So the rewrite rule I need is to redirect all existing URLs - e.g. example.com/drupal/some_section/somepage to example.com/some_section/somepage etc.
How do I do this?

Try this:
RewriteEngine On
RewriteBase /
RewriteRule ^drupal/(.+)$ $1
Hope this helps

Rewriting URLs like example.com/drupal/... will help if people go to example.com/drupal/... but it seems you want it the other way: people use example.com/... and go to you site.
For that, I think you need to change the DocumentRoot in your web server configuration or setup a virtual host for example.com

Related

How to access my single wordpress site via multiple sub-domain

I want to access my single worpress installation site via multiple subdomain without using multisite functionality.
What i have tried, but i have not found the perfect solution:
I have used the MultiDomain plugin but it restricted me to add the multiple domain in array through hardcode, actually i want the subdomain ui plugins that help me to add multiple subdomain like "myname.example.com" to redirect in main wordpress website i.e "example.com".
Thanks in advance
You can configure that easily in apache using NameVirtualHost, no need for a WordPress plugin.
<VirtualHost *:80>
ServerName *.example.com
# for a single subdomain:
#ServerAlias myname.example.com
Redirect permanent / http://example.com
</VirtualHost>
If you don't have direct access to your apache config, you can configure *.example.com to it's own document root (how to do that depends on you hoster, can't give you any concrete examples) and configure the redirect in a .htaccess file:
RewriteEngine On
RewriteRule ^(.*)$ http://example.com/$1 [R=301,L]

.htaccess to rewrite to subfolder & different URL

I've got a site that's setup as a WordPress network/subsite off primary url.
domain.org/subsite
I'd like to rewrite requests from a seperate DNS name - call it domain2.org - (which I control) to that subsite
domain2.org -> domain.org/subsite
I've seen examples of using .htaccess rewrites to route to subfolder, but can't figure out specifics on how to do this.
Thanks for looking.
put this code in your DOCUMENT_ROOT/.htaccess file of domain2:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?domain2\.org$ [NC]
RewriteRule ^ http://domain.org/subsite%{REQUEST_URI} [R=301,L,NE]
I had an experience working with wordpress multisite which is hosted at godaddy.
Godaddy has an option for the registered domain say for eg http://domain2.org asked for hosting server point or url. In the url field paste it http://www.domain.org/subsite
So check with your hosting provider.

Apache redirect to another server keeping browser address

A have a custom website based on apache/php. I also have a wordpress blog and I would like it to be hosted in a different server.
I have tried to create a sub-domine like http://blog.mydomine.com but i would like to keep the old address (http://www.mydomine.com/corp/blog) for SEO purposes. I added the following configuration tu my .htaccess file.
RewriteCond %{REQUEST_URI} ^/corp/blog
RewriteRule ^(.*)$ http://blog.mydomine.com/$1 [L]
I would like to know if I can tell apache not to change the browser address after redirect the request. I know that I could do a 301 redirection but i would prefer to keep the old address.
Any ideas? Thanks in advance!! :)
Use the P flag
http://httpd.apache.org/docs/current/rewrite/flags.html#flag_p
RewriteRule ^(.*)$ http://blog.mydomine.com/$1 [P]
You could try a reverse proxy...
ProxyRequests Off
ProxyPreserveHost on
ProxyPass /corp/blog http://blog.mydomine.com/
ProxyPassReverse /corp/blog http://blog.mydomine.com/
ProxyPassReverseCookiePath /corp/blog /
This requires mod_proxy be installed and enabled.
Note that this will only work in the following contexts per the apache doc: server config, virtual host, directory - this means that putting it in a htaccess file won't work.
What you're wanting isn't really possible. It's not Apache that's displaying the address, it's the web browser, and there's no way (thankfully) to tell a web browser "go to site A, but tell the user it's site B."
You could fake this behavior using a frame page on your main site, but since you're wanting this for SEO I don't think that would help.

static to static url rewrite with htaccess with wordpress

I have a wordpress site with its own .htaccess automatically generated (because I'm using permalinks), than, my web-admin has configured apache to redirect any third level domain to my site, ie :
http://lol.example.com redirects to http://example.com
and than .htaccess with permalinks rules does the rest.
Now I want to write a rule in the .htaccess file that, when a user types a specific third level domain, redirects to a specific subfolder of my site, ie:
http://sprock.example.com/ redirects to http://example.com/mysprockfolder/
I know my question might sound weird, but I've never done this before so I'm quite confused.
Solved with that regex in my .htaccess:
Right before this comment (just in case you have WordPress installed):
# BEGIN WordPress
I've added the following:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?thirdlev\.example\.com [NC]
RewriteRule ^(.*)$ http://example.com/myfolder/ [R=302,L]
with a 302 redirect, everything is good!
it would be much easier for you to just go to your ftp manager and make a subdomain forward to a link. Or, you can make a redirect using php.
when redirecting make sure to add the http://www. or it will think you want to redirect to a part of your page on the site, also make sure that your subdomain has its own folder with its own files and images.

How do I create a redirect from a subdirectory to the root domain?

I am trying to redirect all requests to domain.com/drupal to domain.com, including all sub directories in /drupal.
I have seen several answers telling me how to accomplish the opposite of this with .htaccess, but nothing to go this way. I have tried the following line in .htaccess-
RewriteRule /drupal/* ^/(.*)
as well as several variations of the above, based on those answers, but haven't had any luck.
Thanks!
Try this line:
RewriteRule /drupal/(.*) /$1 [QSA,L]
Let me get this straight ... You have an installation of Drupal in <DocumentRoot>/drupal/. You do not want to alter the drupal installation directory, nor you want to change DocumentRoot in your webserver config. You want to redirect any request, for example /foobar.php, into the drupal directory, resulting in maybe /drupal/foobar.php. And all that without exposing the whole stuff to the user. Right so far? OK, I can only assume that you have an Apache webserver, else .htaccess would not work...
First, make sure that you actually are allowed to use .htaccess, so check on the relevant AllowOverride directive in your apache config.
Then try it this way in your <DocumentRoot>/.htaccess:
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/drupal.*
RewriteRule ^/(.*)$ /drupal/$1 [P]
RewriteCond ensures that you do not run into an infinite loop. The first part of the RewriteRule is always the URL requested by the client. We prefix the part matched inside the parentheses with /drupal/ and force it to be a proxy request via [P] so that apache would only do an internal redirect (instead of sending the client a "Document has moved" redirection code).
BTW: I did not test it. I may have typos in the code. Read http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html#rewriterule for more information.

Resources