Have WordPress with a different index file for testing - wordpress

A site I'm designing a website for was built with static HTML files. I'm converting it to WordPress but I need the old site to still function while WordPress is installed in the same directory (e.g. have index.html be the default one and then have WordPress be something like indexNew.php)
So they go to http://domain.com/indexNew.php to see updates to the new website until it's finished.
How would I configure that in the .htaccess file?

You can use a .htaccess with a simply rule to redirect users to index.html except you :
RewriteEngine on
RewriteCond %{REQUEST_URI} !/index.html$
RewriteCond %{REMOTE_ADDR} !^123\.123\.123\.123
RewriteRule $ /index.html [R=302,L]
Replace 123.123.123.123 by your public ip adress.

You should use your .htaccess to set the default document order:
Tired of having yoursite.com/index.html come up when you go to yoursite.com? Want to change it to be yoursite.com/ILikePizzaSteve.html that comes up instead? No problem!
http://www.javascriptkit.com/howto/htaccess6.shtml
In your case, you won't need to rename the index.php at all - this will do the trick:
DirectoryIndex index.html index.php
Anyone who requests yoursite.com will see the content from index.html. To see the new Wordpress content, just navigate to yoursite.com/index.php

Related

Moving WordPress from subdirectory to new domain

I have a WordPress site stored and served from in a subdirectory: eg https://example.com/en/
We now need to serve it from the root of a new domain eg https://exampletwo.com/, ideally without moving the installation. The domain is already setup as a parked domain on the cpanel and serves the WordPress site correctly.
Changing the siteurl and homeurl automatically redirects https://example.com/en/ to the new location https://exampletwo.com to the correct location and works fine as expected.
The problem is with external links:
https://example.com/en/ now returns a WordPress 404 error. Setting up a page called /en/ putting a redirect to https://exampletwo.com/ works fine. A bit clumsy but works for now.
However they also used to have pages like
https://example.com/en/contact and these return server 404 errors outside of WordPress, i.e.:
The requested URL /index.php was not found on this server.
I'm trying to avoid physically moving the WordPress installation. I'm guessing that when making a request to the /en/ directory, it's actually looking for resources in the /en/en/ directory.
Is it possible to accomplish this using .htaccess / WordPress or some other method or am I best to move the installation to a new location
Thanks for any thoughts
This would be the .htaccess code you'd need in the example.com/en/ folder to redirect everything to the exampletwo.com domain. Again, it would go in the /en/ folder and not the root folder for example.com
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example.com [NC,OR]
RewriteCond %{HTTP_HOST} ^www.example.com [NC]
RewriteRule ^(.*)$ http://exampletwo.com/$1 [L,R=301,NC]

Replace index.php with htaccess rewrite

I'm using wordpress and it run will index.php on root. How do I make one of my folder, says its name is script to run instead of index.php using htaccess rewrite? Redirecting is one of the way but that's not what I want, because it can't retain the URL. I want example.com to serve the content of example.com/script without changing the url.
You can use DirectoryIndex
DirectoryIndex script
This will internally map your homepage to /script
another solution is mod-rewrite
Put the following rule above your existing rules after the RewriteEngine directive :
RewriteRule ^$ /script [L]

wordpress home page use from different directory

I have wordpress installed on my root folder directory files are like public_html/wp-admin, public_html/wp-content etc..
I want it when my site "www.example.com" is visited it will read another folder in the subdirectory eg (public_html/showhomepage)
where showhomepage has a static index.html with css, images etc
Is this possible?
In your wordpress/index.php:
header('Location: showhomepage');
Or you can set up a rewrite rule in your .htaccess file:
RewriteCond %{DOCUMENT_ROOT}/index.php !-f
RewriteRule . /showhomepage [L]
Or something along those lines. Apache has good on mod_rewrite and there's plenty of supporting sites to make some of the explanations more clear.
I may be mistaken but, that redirects requests to your site to showhomepage. I'm not an expert at rewrite rules but I think you can suppress the path with REQUEST_FILENAME in your rewrite conditions.

Removing Wordpress directory name from certain URLs using .htaccess

So I have one Wordpress install in a sub-directory. (www.mysite.com/wp/)
What I need is for certain pages to remove the WP directory name from the URL.
so 'www.mysite.com/wp/careers' needs to be -> 'www.mysite.com/careers'
I have an .htaccess in the root directory and in the wp directory. I've gotten some of my rules to work when permalinks are disabled in WP, but when those are enabled (which they need to be) the WP .htaccess overrides any rules I have in the root.
Is there any way to have 2 htaccess co-exist in this manner? Sorry I haven't messed with wordpress and apache very much.
Any input is greatly appreciated.
**So I finally got this working, it was just a matter of like you said formatting redirect URL so wordpress likes it.
So in my root htaccess file : for this url mysite.com/careers
RewriteRule ^careers/?$ wp/index.php?pagename=careers [L]
And voila and it started working just fine.
Yes, you can have rules in both htaccess files but it's going to be tricky as wordpress has specific ways that it will expect URLs to look.
In the wordpress htaccess file, above any wordpress related rules, add:
RewriteCond %{THE_REQUEST} \ /+wp/careers
RewriteRule ^ /careers [L,R]
then in the htaccess file in the document root add:
RewriteRule ^careers$ /wp/careers [L]
But again, depending on what wordpress expects the "careers" URL to look like, this may not solve your problem.

htaccess redirect to wordpress if I type domain.com/index.php

I've been trying to figure this out but no success. I have a static site in domain.com/site/index.html but I'm also creating a new wordpress version in / to eventually replace it.
What do I put in .htaccess so typing domain.com opens www.domain.com/site/index.html (static website) while typing domain.com/index.php opens the Wordpress site? Is this possible?
Edit: I deleted the previous .htaccess code I posted here. It just didn't work.
%{HTTP_HOST} is just the host name (e.g. "www.domain.com"). To test the path after the host name you need to use REQUEST_URI
RewriteCond %{REQUEST_URI} !^\/index.php

Resources