php


can I put index.php in a subdirectory, but not display subdirectory in url?


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?
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
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.
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>

Related Links

How do Python and PHP compare for ecommerce?
Wordpress PHP If else help
Changing upload_max_filesize on PHP
php session and path setting
php script Config settings
PHP SOAP client that understands multi-part messages?
php check if domain equals value, then perform action
How can I implement RSS 2 in Code Igniter?
Error with MySQL syntax using REPLACE INTO
how to store chechbox value in php
mysql muliple queries in one statement
PHP Static Variables
php code analysis
PHP Object Validation
How to use cms systems like drupal and so on for crawl only? [closed]
How do I loop through MySQL results easily?

Categories

HOME
opengl
plesk
svn
apple-push-notifications
kendo-dropdown
antd
dry
risk-management
whmcs
jersey-2.0
clone
google-search-console
selection
port
xades4j
match
phpstorm-2017.1
grocery-crud
distributed-computing
mixpanel
robolectric
codefluent
jest
unity-container
gollum-wiki
acl
intel
quantitative-finance
perfino
pyopencl
managed-c++
plyr
math.js
acrobat
monitor
epplus
caesar-cipher
cucumber-junit
advanced-filter
cmis
dreamfactory
ms-dos
linq.js
spooler
doctrine-extensions
windows-media-player
sonarqube5.2
nonlinear-functions
sonicmq
android-sharing
patternlab.io
kendo-treeview
email-injection
yargs
google-identity-toolkit
msg
visual-studio-monaco
jsf-2.3
qtcpsocket
node-glob
processor
urbit
utf-16
django-validation
css-paged-media
unhandled
mobilefirst-server
karma-coverage
ocmockito
subfolder
text-align
adhoc-polymorphism
back
screwturn
forio-contour
meteor-collections
san
yii-booster
jquery-transit
virtual-channel
notin
spiral
audiotoolbox
filelock
winsxs
kernel32
airprint
ognl
resharper-5.1
data-retrieval
main-method
downcasting
icon-language
server-load
account-management

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App