Creating a beta version of site on subdomain - php

I have a website that I have been working on for a while. All this time I have been editing the live website files on the web server for my development. I finally realized that it was stupid to edit the live site. My "quick" solution is to copy everything from example.com to beta.example.com. I will edit the beta subdomain and when I have a feature to release, I will copy and replace the existing code on the example.com site. Great.
That would be great if I could get it to work. I'm having troubles with my .htaccess files for both domains and URL rewriting.
For my example.com site, I use a .htaccess like so: (there are only a handful of pages on my site)
RewriteEngine On
RewriteCond %{HTTP_HOST} !^example.com$ [NC]
RewriteRule ^(.*)$ http://example.com/$1 [R=301]
RewriteCond %{REQUEST_URI} ^/recent
RewriteRule ^ recent.php [NC,L]
RewriteCond %{REQUEST_URI} ^/about
RewriteRule ^ about.php [NC,L]
RewriteCond %{REQUEST_URI} ^/category/(.*)/(.*)
RewriteRule ^ category.php?id=%1&name=%2 [NC,L]
RewriteCond %{REQUEST_URI} ^/category/(.*)
RewriteRule ^ category.php?id=%1 [NC,L]
The problem with the beta.example.com site is that it always redirects to just regular example.com. It removes the beta subdomain.
What is the proper .htaccess code to get subdomain sites separate from non-subdomains?

You have to configure settings for beta.example.com on your server. Setting like DNS in the domain account and if you are using windows(IIS)/linux(Apache) server then configure it same way as you have configured example.com.
If you are using shared hosting then you must have CPanel for your website. then create new directory through that and point the beta.exapmle.com to that directory.

Related

Rewrite live site front-end to subfolder (but not /admin) and nothing on localhost

Lots of info nearly solves this, but nothing will quite crack it yet.
The site has a front-end (all in root basically), and an admin panel living in /admin. Basic stuff.
The site runs remotely on http://www.example.com and locally on http://foo
I want nothing locally redirected at all.
On the live server I just want front-end traffic redirected to a sub-folder /coming_soon but no redirection on the admin panel. So the client can start work in admin, but the public will only ever see the content in /coming_soon. (Plus I guess the admin login page, but that's fine).
Closest I came was:
<IfModule mod_rewrite.c>
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} !=foo
RewriteRule ^$ /coming_soon [L]
</IfModule>
But that let me hit the "real" front-end by browsing directly to http://www.example.com/index.php
Your help much appreciated.
Hopefully I got your question right^^ Wasn't sure about the /admin part, who should access or if possible no one or...But the following is my take on your problem:
RewriteEngine On
#excludes HOST=foo and URI=/admin from rewrite to /coming_soon
RewriteCond %{HTTP_HOST} !^foo [OR]
RewriteCond %{REQUEST_URI} !^/admin
RewriteRule ^ http://www.example.com/coming_soon [R=301,L]
You can additionally set a location-directive and only allow entering /admin from specific IP(s).
<location /admin>
required ip 10.11.12.13
required ip 20.30.40.0/24
</location>
update
RewriteCond %{HTTP_HOST} !=foo
RewriteCond %{REQUEST_URI} !/(coming_soon|admin)
RewriteRule ^(.*)$ /coming_soon [R=302,L]
And R=302 is just temporary rewrite = won't be cached by browsers with target location. R=301 would tell browsers to save the target /coming_soon right away.
...if any one can improve this, or make it more elegant, I'd love to hear!
RewriteCond %{HTTP_HOST} !=foo
RewriteCond %{REQUEST_URI} !/coming_soon
RewriteCond %{REQUEST_URI} !/admin
RewriteRule ^(.*)$ /coming_soon [R=302,R]

At apache server, several address to one domain

I have been developing web application using php framework - codeigniter at apache server.
For example, My server address has three address - 10...*, www.test.com, test.com
In codeigniter framework, I set the base url in config.php
$config['base_url'] = 'http://www.test.com/';
so I want that clients' requests will be redirect the www.test.com address.
That is,
http://test.com/ =======> http://www.test.com/
http://10.*.*.*/ =======> http://www.test.com/
In documentation, it talk me I have to use .htaccess file.
But, I don't know about it.
How to redirect the several address to one address?
In your htaccess file for the site you can use the following
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.test\.com$ [NC]
RewriteRule ^(.*)$ http://www.test.com/$1 [L,R=301]
</IfModule>
In case you haven't used mod-rewrite before, it needs to be enabled on your server. The .htaccess file needs to go in your document root folder, usually public or public_html.
Here are some instructions for enabling modrewrite on apache under Ubuntu. If you let me know what server or hosting you are using I may be able to point you to some better instructions. Note: You will probably find it's already enabled for you!
https://www.digitalocean.com/community/tutorials/how-to-set-up-mod_rewrite-for-apache-on-ubuntu-14-04
That should do it.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} ^10\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
</IfModule>
1st condition of each block means: host is not empty
2nd condition of 1st block means: host doesn't match www.*
2nd condition on 2nd block means: host matches an ip address starting with 10, it would match invalid ip aswell such as. 10.256..
Then redirecting (or rewriting) the request where 301 means permanent and L means stop rewriting.
For this to work, you'll need mod_rewrite enabled in apache.

http and https redirect to different link with wildcard subdomain

I am deploying a PHP web application into a linux server for my client.
Their linux webserver allows wildcard subdomain, the server have SSL on.
I have set up the virtualhost for the wildcard subdomain and no problem occurs,
the problem is when i tried to use http:// instead of https:// on a wildcard subdomain, it links to other URL, it links to the clients own application.
I tried asking them about their server setting that redirects the non-https and they said they have no idea.
I tried modifying the .htaccess to redirect any http request to https but it does not work too, I suspected that there must be a missing server setting that caused this.
I have little knowledge on linux web server, and am really confused where should I even begin to search for this kind of problem, I've tried google for days and have not been able to find any solution.
here is my .htaccess setting, i put it on the root application.
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [QSA]
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301]
the first rule is to delete index.php from the link, it works perfectly fine.
the second one is to redirect from http to https.
Any kind of answer or insight are very appreciated

Move main site into subfolder (htaccess)

Need to organize several sites in one hosting account, putting each into its own folder.
Via CPANEL, this is completed and working for the add-on domains, but the main site (with all its subfolders) also needs to be in its own folder.
I have been doing this via PHP:
example.com/index.php :
<?php
header('Location: subdir/mainsite/index.php');
?>
The down side is that there is a page flash as the site redirects.
Another downside is that the URL reflects the new location in the address bar:
http://example.com/subdir/mainsite/
I just want visitors to see http://example.com
I suspect this can be resolved by using htaccess instead of PHP.
So, if my domain is:
http://example.com
And I place the main site files in:
public_html/_sub/mainsite
And the add-on sites must continue to work...
What would the htaccess look like?
This is what I have thus far:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?example.com$
RewriteCond %{REQUEST_URI} !^/_sub/mainsite/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /_sub/mainsite/$1
RewriteCond %{HTTP_HOST} ^(www.)?example.com$
RewriteRule ^(/)?$ _sub/mainsite/index.php [L]

.htaccess file configuration for public section of my website

I am trying to deploy my site online and the .htaccess file which worked perfectly in the localhost seem not be be working the same way on my share hosting domain.
i have a public folder in the root(htdocs) folder which is meant to serve the public files and I used two .htaccess files one in the public directory and the other in the the root(htdocs) folder.
.htaccess for htdocs folder
RewriteCond %{HTTP_HOST} ^mysite\.morehere\.net$ [OR]
RewriteCond %{HTTP_HOST} ^www\.mysite\.morehere\.net$
RewriteCond %{REQUEST_URI} !^/public/
RewriteRule (.*) /public/$1
and that of the public directory
# --- Homepage
RewriteRule ^home$ index.php [NC]
RewriteRule ^home/$ index.php [NC,L]
# --- articles page
RewriteRule ^articles $ articles.php [NC]
RewriteRule ^articles /$ articles.php [NC]
........
My intention is to make the URLs search engine friendly and appealing to users.
Edit: I have made sure mod_rewrite on the production server is turns on but the pages still gets redirected to the not found page.
Like mysite.morehere.net/home/ is redirected to the not found page
Can anyone please help me out to figure out where the problem is.
Check if mod_rewrite is turned on, on your production server

Categories