I didn't quite find what I need despite I'm sure it is asked before..
I need to rewrite index.html to a subdirectory but allow index.php to be visited.
I have a Wordpress installe in the root, but as long it is in dev I would like it to be visited if addressed directly with exact path and all visitors writing the domain only to be redirected. Thought and tried todo this with .htaccess
Redirect /index.html http://www.example.com/home
But this redirects also index.php to the subdirectory.
I also tried adding
remove_filter('template_redirect', 'redirect_canonical');
To the functions.php
What next?
Put the following code at root .htaccess file :
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/home/
RewriteCond %{REQUEST_URI} !^/index.php
RewriteRule ^(.*) /home/$1 [L,R=302]
the above code will redirect any request to /home/ directory including main domain and excluded only the index.php
for example if request site.com/page it will go to site.com/home/page
if you request site.com it will direct you to site.com/home/
but if you request site.com/index.php it will go to site.com/index.php
Related
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]
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]
Is it possible to redirect a directory and all its sub-directories to another location with a single redirect rule within wordpress´ htaccess file?
e.g.
http://example.com/old
http://example.com/old/foo
http://example.com/old/foo/bar
move them all to
http://example.com/new
--
when I try this
RedirectMatch 301 ^/old/(.*)$ /new/
while pointing to
http://example.com/old/foo/bar
it ends up with
http://example.com/new/bar
You can put this rule in your htaccess (before Wordpress' main rule, after RewriteEngine On line)
RewriteRule ^old(/.*)?$ /new [R=301,L]
Note: you may have to clear your browser cache since your old rule is stored into it
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
I recently moved my WordPress website to a subfolder. I want to add a redirect in the .htaccess file so that the links to images I've uploaded originally to ~/wp-content/uploads/ will pass to ~/blog/wp-content/uploads. The .htaccess file must remain in the root folder for WordPress to read it properly. This is what I tried
Redirect /wp-content/uploads/ /blog/wp-content/uploads
That worked great, except I host other domains on this account, and all of the other domain's upload folders were being redirected in a similar manner.
Is there a way to restrict this redirect to just one domain? So that example.com/wp-content/uploads redirects to example.com/blog/wp-content/uploads, but another.com/wp-content/uploads does not?
Thanks everyone!
Assuming you want a 301 redirect, using this RewriteEngine example should work:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?example.com$ [NC]
RewriteRule ^wp-content/uploads/(.*)$ http://www.example.com/blog/wp-content/uploads/$1 [R=301,L]
You should place the Redirect inside the <VirtualHost> definition for example.com in the httpd.conf (or equivalent) instead of .htaccess
on a sidenote, Redirectsays temporary / 302 by default, so it is nicer to use
Redirect permanent /wp-content/uploads/ /blog/wp-content/uploads instead