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

AJAX request waits for another request to finish
How can I use “openssl_x509_parse” for expired/error certificate in PHP?
Upload Files directly to Amazon S3 bucket the progress bar is not working correctly using Laravel 5 and DropZone Js
Websocket Connection closed before receiving a handshake response
missing id passed in urlindent
phpunit mock function inside value
Insert event in google calender
Break Up Array and output to table?
Opening an image from a url in PHP[closedd]
PHP : Returning two separate queries different results within a function in php
How to write a Function to scan & remove similar words from a large variable using PHP? [duplicate]
alert messages not showing and how to produce preventing unique username messages?
Is there a php function to determine whether an array element has changed?
symfony3: form action not working (and happy for it)
PHP Thread Segmentation fault Error
How to remove slashes from array key using php

Categories

HOME
opengl
magento2
tomcat
typelite
opencv-python
barcode-scanner
redmine
foaf
website
openlayers-3
google-play-services
material-components
dji-sdk
ui-automation
native-base
responsive-design
lc3
migrate
scrape
lapack
locationmanager
circleci
vimeo
ex
webstore
salt-cloud
angular2-highcharts
azure-machine-learning
unity-container
bosun
chronicle-queue
pyopencl
offline-caching
android-service
math.js
pyspark-sql
basic-authentication
xenapp
source-insight
argv
rust-cargo
creation
grails-2.5
textmate2
windows-store
python-jira
yoast
dredd
cordova-ios
skip-lists
watir-webdriver
stateless-session-bean
email-forwarding
sesame
email-injection
controllers
s-function
system.web.optimization
pyaudio
maven-release-plugin
deferred-rendering
unsigned
android-syncadapter
simian
wif4.5
flask-security
juniper-network-connect
variable-length-array
jnlp
gql
green-threads
kefir.js
mod-auth-openidc
jcheckbox
back
jack
iosched
assetic
django-settings
mute
non-ascii-characters
iirf
proc-open
linkbutton
nsmutablestring
stretch
hardcode
wcf-callbacks
dynamic-c
getopts
database-deadlocks
gaelyk
active-record-query
principles
resharper-5.0
.net-client-profile
index.dat
icon-language

Resources

Database Users
RDBMS discuss
Database Dev&Adm
javascript
java
csharp
php
android
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App