The customers existing site is running nicely on the server from /home/nfc/public_html at the URL www.example.com.
We've developed a new site under /home/nfc2/public_html and this has been checked by using a development URL such as nfc2.dev.example.com.
But now I want to test for various links etc and check all works as expected.
Is there a way I can get Apache to serve me the new site if I browse to www.example.com but still show everyone else the old site.
It may be possible by using SetEnvIf REMOTE_ADDR type stuff to give me a specific site due to my IP address.
This may seem like not really needed - but the reason is that we have developed six sites at the same time and they all have many links between them - and currently those links go to the dev addresses so the customer could check all sites at the same time. I'd like to view the new sites on their new URL's so I can check all links have been altered.
You can just use a RewriteRule with the appropriate RewriteCond using mod_rewrite.
Example on remote_host:
RewriteEngine on
RewriteCond %{REMOTE_HOST} !^.+\.ourdomain\.com$
RewriteRule ^(/~.+) http://www.somewhere.com/$1 [R,L]
Or by address:
RewriteCond %{REMOTE_ADDR} ^123\.45\.67\.[8-9]$
Related
I have 2 domains, lets use these as examples:
business.com
mystore.com
Currently, the business.com domain loads the store pages using this structure.
business.com/mystore
business.com/mystore/search
business.com/mystore/catalogue
In this case, those are the urls for a store called mystore. Since there can be any amount of stores inside the business.com domain, this is the current .htaccess rewrite rules:
RewriteRule ^([0-9a-zA-Z-]{2,50})/?$ store/index.php?store=$1 [QSA,L]
RewriteRule ^([0-9a-zA-Z-]{2,50})/buscar$ store/search.php?store=$1 [QSA,L]
RewriteRule ^([0-9a-zA-Z-]{2,50})/catalogo/?$ store/catalogue.php?store=$1 [QSA,L]
That works great for basic profiles; but now I need to activate a premium kind of profile, where the stores can use their own domain, so that this should be the new structure for that particular store:
mystore.com/
mystore.com/search
mystore.com/catalogue
Both domains are in the same managed apache server. Is there a way via the .htaccess file from mystore.com, where I could actually catch any requests and then actually request the value from business.com/mystore/* ? So, for example:
mystore.com/catalogue/nice-product/384
actually retrieves the result from
business.com/mystore/catalogue/nice-product/384
Just for clarification, the actual path of each domain root in the server, is:
/www/business/html
/www/mystore/html
All ideas welcomed, thanks!
Okay...i am doing something kinda strange and out of the ordinary. I will try to explain...
I have several domain names pointed to the same root directory on my webserver. I can access the entire website using any of the domain names (I know this is bad for SEO, but there are reasons). Additionally, none of the "pages" really exist...as they are all being built dynamically...so i have some mod rewrite rules set up to point all incoming queries to view.php and passing in variables to generate the page content...anyway...
What i want to do is set ONLY THE HOME PAGE of two of my domains to (invisibly) use content of an existing sub page. Here is an example:
These all are the same page:
www.domain1.com/process/
www.domain2.com/process/
www.domain3.com/process/
which is really doing something like: view.php?page=process/
I want this page to display for www.domain2.com (and still also be accessible at domain2.com/process)
Essentially, there is a sub page of the site that i want to serve as the "HOME" page for domain2.com and domain3.com but if domain1.com should still use the default (index.php) HOME page.
I am sure i will need to post clarifications to this once replies start coming in...but here is what i have at the moment:
# special rules to set other domain names default homepage as specific internal page
RewriteCond %{HTTP_HOST} ^www.domain2.com [NC]
RewriteRule ^(.+)?$ /view.php?page=process/ [NC,L]
Currently this is sending ALL traffic to domain2.com to the "process/" page...so it is blocking out all other pages. I need to know how to have this rule ONLY apply to the base domain without any extra query string or url path. The key is that i DO NOT want to affect other pages within the domain...so i shoudl still be able to browse the whole site using this domain name...i just get started on a different view.
To only match the homepage, i.e. http://domain2com/ you need to match the empty path (as mod_Rewrite removes the leading /.
RewriteCond %{HTTP_HOST} ^www.domain2.com [NC]
RewriteRule ^$ /view.php?page=process/ [NC,L]
I'm developing a webapp and for the static files I'm simply using apache at localhost while the backend is on a couchdb instance running at localhost:5984.
The webapp interacts with files from the backend all the time. So what is happening when trying to test on apache all file requests to localhost:5984 are getting blocked due the cross-domain policy so the only way to get that working is starting the browser by setting flags to ignore that.
But again I get stuck when trying to test the app on mobile such ipad or iphone.
Currently I have this on my .htaccess file.
RewriteEngine on
# these are 302 http redirections instead of serving as a proxy
RewriteRule auth http://localhost:5984/auth [L]
RewriteRule db/([\s\S]+) http://localhost:5984/db/$1 [L]
RewriteRule send/([\s\S]+) http://localhost:5984/send/$1 [L]
# these are just redirections to static files and work great
RewriteRule ^([a-z/.]+) _attachments/$1 [L]
RewriteRule ^$ _attachments/ [L]
As you can see I have really no idea on how to deal with apache configuration unfortunately.
But what is happening right now is that for some of these rules apache is simply redirecting the page instead of provide it as a proxy server which causes the issue with cross-domain.
Also on the first auth rule I send POST and DELETE requests which as a redirection instead of proxy it won't pass the data being POSTed through.
So what I would like to achieve is to activate some kind of feature (if it exists) which will make apache simply render the page as it was on the localhost domain instead of redirect it. (I named this a a proxy, but perhaps that's not even the right term, sorry for any mistake committed with the nomenclatures).
Is is possible to achieve such action?
Thanks in advance
Have a look at these links / options:
[P] flag:
http://httpd.apache.org/docs/current/rewrite/flags.html#flag_p
http://httpd.apache.org/docs/current/rewrite/proxy.html
mod_proxy (possibly -- but I think #1 should be enough if it's on the same server):
http://httpd.apache.org/docs/current/mod/mod_proxy.htm
My webserver is hosting many apps whose path looks like
http://example.com/app1/
http://example.com/app2/ ...
I wanted to have temporary links to these apps which can be easily configured to be expired. So I have maintained mapping of temp to app url with expiry time in mysql.
In apache I have written rewrite rule as below
RewriteEngine On
RewriteMap linkmap prg:/home/http/a.php
RewriteCond $1 ^[^/]*$
RewriteRule /(.*) /$1/ [R=301,L]
RewriteRule /(.*) /${linkmap:$1} [P]
a.php maps temp urls to actual urls using mysql db. For example
temp1/xyz --> app1/xyz
Everything works fine until any page in app1 tries to redirect to another page. Since I am mapping urls based on mysql, I am not able to figure out how to make ProxyPassReference to read from mysql and replace redirect urls.
I have tried to specify ProxyPassReference rule manually and it works. But it is not possible to add all rules manually since I can dynamically create links through some interface by inserting links to mysql db.
Please help me to handle redirects.
I have figured it out how to do it.
So from rewriterule I get target url map which I save i regular expression. Then I used ProxyPassReverse with interpolate flag.
There is one problem here. My program to map url is in php. It works fine but If I see it after few days, it seems program is stopped and I get server error then needs to restart server.
My Situation:
I implemented an apache Rewrite Map to redirect incoming requests based on a database
RewriteEngine On
RewriteMap dbapp prg:/usr/local/somewhere/dbapp.rb
RewriteRule ^/(pattern)$ ${dbapp:$1} [R]
So far everything works fine, but I want to decide in the dbapp.rb script weather to redirect or give the client a http-status-code-404. I could just deliver a local page that doesn't exist but that doesn't seem right. I also want this to be usable on any server, and redirecting to "localhost" is also not an option ;-)
You could return -, which essentially means: 'no rewrite', but I don't know whether that's supported in a maps/[R] combination. Better may be to check with RewriteCond ${dbapp:$1} !^$ or something that it doesn't contain an empty string.