i have a site abc.com in php and now made anothers site abcd.com on rails, i wish to redirect all requests that go to the php site to redirect to abcd.com...
example:
abc.com/page3 -> abcd.com/page3
abc.com/non_existing_link ->abcd.com
this php site is just hard coded, not using any framework and i wish to write script in index.php which would accept ny link towards abc.com and then check the extension and redirect it accordingly to the corresponding links on abcd.com... i was suggested to write a controller from a collegue and i am not familiar with mvc functionalities nor th controllers class and stuff...
If your webserver runs apache, I would recommend placing a .htaccess-file in the root of your original server as in the following answer: .htaccess redirect all pages to new domain. If you would like to keep the names the same (redirect to exactly the same name on your new domain), use the following lines:
RewriteEngine On
RewriteRule ^(.*)$ http://newdomain.com/$1 [R=301,QSA]
This method works with very limited amount of work/coding :-)
I believe you there are several ways to achieve so:
Using php redirect in all php pages.
How to make a redirect in PHP?
Modifying .htaccess file in your directory
http://kb.mediatemple.net/questions/242/How+do+I+redirect+my+site+using+a+.htaccess+file%3F
If you have a cpanel of other controler system from hosting provider then do it directly there.
Related
I have a website as a side hobby.
I purchase a custom script from a developer. That script is designed to be run on the main domain. like www.example.com
This is because of the script using require_once and include_path function to call files within the script. For example /functions.php or /admin.php
So if I configure it on the main domain it works but on the subdomain, it gives 403 Forbidden error because of the nonexistence of URLs.
I mean for subdomain the directories inside it should be changed to
subdomain.example.com/functions.php or subdomain.example.com/admin.php.
Here is the problem there are more than 100+ pages and it would be quite hard to change it one by one for me.
I am looking if I can do it using .htacess rewrite module.
Is it possible if on page load the directories inside the files can be altered?
I have installed SVN and use it to maintain access to my repositories via the http protocol (http://localhost/svn/project_name/ maps to the physical location /var/www/repos).
I also have Apache installed for my web application (with a physical location of /var/www/web_app). This can be access via http://localhost/, rendering a default action (Presenter: Homepage, Action: default - this yields index.php).
However, when I want to view the Contact Page (Presenter: Contact, Action: default - yielding http://localshots/contact) it says:
NOT FOUND The requested URL /contact was not found on this server.
The error doesn't look like it is a framework error (bad code for routing in the framework or something similar). It looks like there is a conflict between in .htaccess or the apache config.
I'm using a PHP framework (called Nette, but I think it's not important what framework is being used: I think the problem lies between the routing and apache configs).
So, it seems that you have no rewrite rule for the url you are requesting.
2 possibility here, you write a new rule like :
RewriteRule ^[/]*contact$ index.php?page=contact [L]
The second is to modify the url you want to reech like http://localhost/contact.php, then create a php file a the root of your project.
EDIT :
You can also do it like this :
RewriteRule ^[/]*contact$ contact.php [L]
So you have a beautiful url and redirect directly to your file
I've made a new website for a client who has an intranet integrated into their old website.
The new website is currently on a different server, but when the domain A records point to the new server, the old site (and intranet) will obviously not be accessible, but I need to keep their intranet active. The path to their intranet is: abc.com/intranet
Is there a way to have URL path direct to the old server? For example:
abc.com - new website loads on new server
abc.com/intranet - old website loads on older server
If it's not possible, I suppose I'm looking at creating a sub-domain on abc.com for the intranet. Any thoughts are appreciated.
You need to use an Apache RewriteRule using mod_rewrite. This can be placed in an .htaccess file on your server’s root or it can be placed directly into your Apache config file.
If you want to redirect example.com to example.com/intranet, then this is the Apache RewriteRule that should work for your needs:
RewriteEngine on
RewriteRule ^(.*)$ /intranet [L,R=301]
This will grab any URL on the site this RewriteRule is placed on & redirect them to /intranet. That /intranet can also be a full URL such as this example below:
RewriteEngine on
RewriteRule ^(.*)$ http://example.com/intranet [L,R=301]
EDIT: Upon rereading your question, I am not 100% sure the answer above works for you as-is. So I think if you are describing how to point one URL path from one server to another, you would do this. This gets placed on the new server:
RewriteEngine on
RewriteRule ^/intranet(.*)$ http://old_example.com/intranet [L,R=301]
That would grab any URL coming from new_example.com/intranet and redirect it to old_example.com/intranet.
ANOTHER EDIT: Since the original poster indicates the server will have the IP fully changed, then a subdomain for the old server is the best way to go. You can’t redirect content on one domain the way you describe if you switch the domains fully to different IP. Both servers need to be active with an active—but different—domain name for what you want to happen.
abc.com/intranet is a path in the virtual file system exposed by your web server, so is not possible to serve the content from different web server. You have 2 options here.
Put a reverse proxy in front of both servers and get the content from server A or B based on the original client request.
As you said, create a subdomain and also redirect /intranet to the new subdomain.
Hope this help!
Current versions of MediaWiki have the front page accessible via
http://www.example.com/wiki/index.php/Main_Page
Instead of the older version of
http://www.example.com/wiki/index.php?title=Main_Page
That second URL is literally how the PHP script would be called in most casual web apps, but the above URL is cleaner and more desirable. Now, I can see how that could easily be converted with an Apache mod_rewrite rule:
RewriteRule ^/index.php/(.*)$ /index.php?title=$1
But there's no htaccess file in the default MediaWiki setup. So how are they doing the redirect?
Not sure if this is what they are doing, but there no need to redirect using a .htaccess. the page index.php is found and that script is what is loaded. index.php just gets $_SERVER['REQUEST_URI'] and parses that into the query string.
http://httpd.apache.org/docs/2.0/mod/core.html#acceptpathinfo
Is it possible to make the website unavailable while editing it, while online?
If so, what is the method called and how is it done?
I have a webhosting company so it's not my own server!
Typically, people use the .htaccess to password protect it until you are ready to show it to the world
Here is a link to an article with instructions
http://www.elated.com/articles/password-protecting-your-pages-with-htaccess/
I had the same issue, I just put up a "coming-soon.html" page and redirected everyone without my IP there via htaccess, here's the question on SO: Want to redirect all visitors except for me [.htaccess]
Or, if it's ASP.Net - place a file called app_offline.htm in the site root.
If you are uploading a new version of the site you can create a symlink in the place of the root directory and then switch that when the site's ready. You can also switch the symlink back to the previous version if something goes wrong.
You can make an .htaccess file like this :
RewriteCond $1 !offline.html$
RewriteCond %{REMOTE_ADDR} !^your_ip_adress
RewriteRule ^(.*)$ http://www.mydomain.com/offline.html [R=302,L]
Simply put the files in a new directory and don't tell anybody else the name of the directory. (Or you can tell it to some beta testers if you like.)
When the pages are ready and tested, just move the files into the normal place (after moving the old existing files into backup directory). This way, you always have a working site online.
But generally, it is better to develop the web site on your local computer, not online.