Replace index.php with htaccess rewrite - wordpress

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]

Related

Rewrite index.html (default) but not index.php .htaccess

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

WordPress > htaccess > redirect directory and all its sub-directories to one directory

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

.htaccess redirect in wordpress

I would like users that go to the website 'http://kevingstongramado.p.ht/',
to be redirected to 'http://kevingstongramado.p.ht/catalogo/'. Which is in fact a wordpress website.
I´ve tried this:
Redirect 301 /http://kevingstongramado.p.ht/ http://kevingstongramado.p.ht/catalogo/
Putting the .htaccess inside the root directory of the website. Not the root directory of the folder which contains the wordpress.
Doesn´t work.
"catalogo" is the folder which contains the 'index.php' that opens the wordpress website.
Anyone?
Use RedirectMatch
If I am not wrong, you should use the relative path.
Create the index file index.htm in your root folder. Then,
RedirectMatch 301 /index.htm /catalogo//$1
.htaccess files are calculated by searching and interpreting the configuration for every .htaccess file in every directory in the path under the document root.
You want something along the lines of
RewriteCond ${REQUEST_URI} !^/catalogo/ [NC]
RewriteRule ^(.*)$ /catalogo/$1 [L]
This makes the rule conditional. It will only execute the rule if /catalogo/ is not present in the request uri. And the actual rule says to take everything and put /catalogo/ in front of it... and that it is the last rule to be executed in the file. This file will be reprocessed when it goes to the /catalogo/ directory.

Have WordPress with a different index file for testing

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

.htaccess Subfolder Redirect

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

Resources