Right now the index.html of my website is loading from the root directory when someone enters www.mydomain.com in their browser, which as I understand it is the default behavior. I want to move all of my website files into a subdirectory (e.g. public) so that when someone loads www.mydomain.com, the index.html file it loads is in the /public/ directory on my server. However, I do not want the URL to change to www.mydomain.com/public. From there, if a link is clicked/, all of the files will be in the public directory. How would I go about achieving something like that
You can use this code in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
RewriteBase /
RewriteRule ^((?!public/).*) public/$1 [L,NC]
Related
Simple question, let's pretend I have the following path:
http://example.com/subdir/index.html
I would like to be able to open that index.html page by typing this in the browser:
www.example.com/subdir
and hit enter to have the browser load its included index.html page.
Is that possible?
My goal is to have a few subdirectories with the same root domain (example.com) and be able to open the index.html pages of each subdirectory without having to add /index.html at the end.
Thanks so much!
For sub folders only put this in main root .htaccess file :
RewriteEngine On
RewriteRule ^(.*)/index([\.html]*)$ /$1 [R=302,L]
For entire website change it to this :
RewriteEngine On
RewriteRule ^(.*)index([\.html]*)$ /$1 [R=302,L]
So , any request with index or index.html will be removed .
Note : clear your browser cache then test it , if Ok change 302 to 301 to get permanent redirection
If you server is running Apache, just create an .htaccess file (if you haven't already) and add this line at the top of the file:
DirectoryIndex index.html
I currently use ipage as a host and have a domain pointing to an index.html. However, I need the domain to point to an index.php instead. So I created a .htaccess and only wrote; DirectoryIndex index.php index.html and saved it but it's not working and users are still being directed to index.html. There is one issue and that index.php is inside a folder called "SourceFolder". So I think the server looks for index.php and can't find it.
Your DirectoryIndex directive is fine but you need to route request to correct folder.
Have this code in root .htaccess:
DirectoryIndex index.php index.html
RewriteEngine On
RewriteRule !^SourceFolder/ SourceFolder%{REQUEST_URI} [L,NC]
So your default 'root' directory of the website has a folder in it called SourceFolder, and the index.php file is in there?
If so, then simply do the following inside htaccess.
DirectoryIndex SourceFolder/index.php
This will look for index.php inside SourceFolder.
My friend recently told me that I was able to do something like
http://example.com/about/
without having to create a directory and place a index.html inside of it, like this.
http://example.com/about/index.html
How in the world do you do this? I didn't know it was even possible to do unless you created a directory and placed a index.html inside of it, anyway thanks. :)
If you use Apache as WEB server, use .htaccess for you site root directory.
Write following rule here:
DirectoryIndex index.html
Also you can use more than one file here:
DirectoryIndex index.php index.html
In this case first found will be used.
If you don't want to use .htaccess, you can setup same in Apache config file (httpd.conf):
< Directory /foo>
DirectoryIndex index.html
DirectoryIndex index.php
< /Directory>
Here /foo - root directory of your site
Servers like Nginx can allow you to rewrite URLs, so you can place your file wherever you want.
If you use Apache web server then create a file named .htaccess
and write code like below
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?load=$1 [PT,L]
If this code when you type a url like www.example.com/about its doing to open your aboutController
Write aabout in this url http://salopek.eu/content/28/create-a-simple-php-mvc-framework
If you does not use Apache or you want simple solution then then you can just create a folder named about and create a simple index.html or index.php file. Then when you type www.example.com/about
it opens your about\index.html or index.php file
I hope it helps
I have Wordpress installed in a subfolder: www.mydomain.com/p/
I want the front page of www.mydomain.com to show the wordpress ( /p/index.php ) frontpage. I don't want a redirect.
I have tried with this in my root .htaccess:
Directoryindex index.php /p/index.php
Theres is no index.php file in the root, so it uses the Wordpress index.
It works, but with one problem:
It does not update the page on www.mydomain.com but only on /p/index.php
I use the plugin WP Super Cache.
Is there another solution to doing what i want?
Thanks
The main thing is you can redirect using htacess but my suggestion
you just have to move your file from www.example.com/p/ to www.example.com and change links in database
because each links will redirect from www.example.com/p/
You no need to redirect subfolder to main domain plz move the files to main domain. If u using ftp select files and drag into domain path folder like htdocs / www/ or you can move using cpanel
Otherwise
The possible and simple way in htaccss we can redirect main domain into sub domain.
If you want to do the same as you asked plz refer this link I it will help full.
https://my.bluehost.com/cgi/help/htaccess_redirect
Okay so I want to share the answer I found a while ago:
Go to Wordpress settings -> general settings, set the WordPress Address (URL) to:
http://www.example.com/p
Copy index.php to the root folder.
Edit the root index.php so it includes the wp-blog-header.php from the sub folder:
require('./p/wp-blog-header.php');
The root .htaccess should have this:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
I have a website, say http://mysite.com. I would like to put index.php in a subdirectory, public_html/mysubdir/index.php. I would like public_html/mysubdir/index.php to get executed when the user goes to http://mysite.com. And I would like the url to continue to read http://mysite.com. Is this possible?
If your webserver is Apache you could use URL rewriting with mod_rewrite.
Another option is to create an index.php in the root directory and include index.php in the sub directory.
Rewrite rules may be overkill for this depending on what you want. For just your main index page, this will work...
Simply adding this one line to your .htaccess file:
DirectoryIndex mysubdir/index.php
It will display the page located at mysubdir/index.php while simply showing http://mysite.com in the URL.
I use this method myself. While all of my pages are located in the same subdirectory, the home page is displayed with my domain name by itself (http://www.mysite.com). All other pages show the full URL.
If you also have index pages within deeper subdirectories and want those to come up by default within the subdirectory.
Example:
If you want this page: http://mysite.com/mysubdir/anothersub/index.php
to come up with this URL: http://mysite.com/mysubdir/anothersub/
Then modify the line with another index.php like this...
DirectoryIndex mysubdir/index.php index.php
What this does is tell the server to look for files with those names in that same order. If it can't find the first, it tries the second, and so on.
When you're inside your root at / it finds and then displays mysubdir/index.php.
When you're inside another subdirectory like /mysubdir/anothersub/, it can't find anything named mysubdir/index.php so it goes to the next item and displays index.php
You could use a .htaccess file and define Rewrite rules.
http://httpd.apache.org/docs/current/mod/mod_rewrite.html
Make sure that mod_rewrite is enabled and then place .htaccess file in your root directory with something like this:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ your_subdir/index.php/$1 [L]
</IfModule>