Assume we have a complete web page in /web_page/ directory. Now I want to include the index.php file from /include/ directory, so that /include/index.php will show the same web page as in /web_page/index.php. There are some problems:
This can not be done through iframe.
There are a lot of included files in the /web_page/ directory and simple require_once() causes other includes to be not found.
As #pes502 suggested, it may be better to do this with .htaccess. Try adding this to a .htacess file in the root directory.
RewriteEngine On
RedirectMatch 301 /include/index.php /web_page/index.php
This will send a header that redirects from one page to the other, preventing duplicate pages.
You can use ../ as 'one folder up'. So include should be like:
include_once('../include/index.php');
Related
I have a very peculiar problem. Formerly, I was using Wordpress and I have a link that has a path of http://www.acetraining.com.sg/index.php/contact-us/.
I have just reverted the website to a non-Wordpress and have a static link of http://www.acetraining.com.sg/contact_us.html. How is it possible for me to redirect the old path to this new path? I already have a redirector script and I know I have to place this code :
<meta http-equiv="refresh" content="0; url=http://example.com/" />
to the head region of a html page. What I have done is that I've created an index.php as a folder name and another contact-us as a subfolder and then I created an index.html file within that but it does not work at all.
Any suggestions anyone?
Good morning!
I think that using meta tag for redirection will not good for your SEO. As it is a definite URL moving, I suggest you the header 301 (Redirect Permanent). You can use this by creating a .htaccess file in public_html (or your website public root directory) and put on something like this :
RedirectPermanent /index.php/contact-us/ http://www.acetraining.com.sg/contact_us.html
Hope this may help you.
If you don't have a .htaccess file in your server root!
Create an empty text file using a text editor such as notepad, and save it as htaccess.txt and add the code blow.
Options +FollowSymLinks
RewriteEngine On
# Redirect old file path to new file path
Redirect index.php/contact-us http://www.acetraining.com.sg/contact_us.html
NOTE:
The reason you should save the file as htaccess.txt is because many operating systems and FTP applications are unable to read or view .htaccess files by default. Once uploaded to the server you can rename the file to .htaccess
hopefully it will fix the redirection for you.
Lets say I have the website url www.example.com. My index.php page is in the root directory. I then want to have a page at www.example.com/someDir as well as a page at www.example.com/someDir/anotherDir. I thought that I would make the directory someDir in the root directory and make the directory anotherDir within the directory someDir, then place an index.php page in both those new directories which would be the visible page at those URLs.
Is this the proper way?
Yes.
Note that your web server (apache or whatever) should redirect www.example.com/someDir to www.example.com/someDir/ (with a trailing slash) which will make the relative links work correctly with respect to the index.php files.
Ok so my current sites is on the .htaccess method to block user access to the directory
e.g. http://www.example/_directory/ via Options All -Indexes
Question should I stick with that or is putting an index file e.g. index.php in every directory better? I'm thinking of an index.php that will redirect to the homepage rather than giving users an error 403 page.
Opinions?
It would be clever to build your web site in a way that these subdirectories also have content (e.g. about/ also shows some information, when about/history/ and about/our-company/).
If the directories contain only files, it's IMHO totally fine to just have a 403.
Answers to your questions might be very biased.
If you're on a Unix/Linux server, you don't need to have blank index files at all in your directories. Just create a .htaccess file and put the following code in it:
Code:
Options -Indexes
When anyone tries to access the contents of a directory that doesn't have an index file, they'll get a 403 error.
Ref : http://wildlifedamage.unl.edu/manual/mod/core.html#options
Right now I have a assortment of 9 files (javascript, image, stylesheet, php) in the root directory of my web server. I would like too put all of these files in a directory called home (for home page). So now at this point I can view my home page at http://example.com/home.
I would like it so that when you visit http://example.com/ it points to the files in the home directory.
I am using php so my first attempt was to create a index.php in the root and include the index from home. This breaks relative URLS within styles, javascript, and includes. To combat this I prepended my includes with $_SERVER['DOCUMENT_ROOT'].'/home/. More problems arise when I try to redirect http://example.com/home to http://example.com/.
Is their any better way of doing this, possibly with .htaccess?
Yes, if your server supports mod_rewrite, you could probably add a RewriteRule:
RewriteRule /(.*) /home/$1 [R,L]
In your Apache httpd.conf change the DocumentRoot to your "home" folder.
For example:
www.example.com/about.php
I don't want the files with the extension .php to be available to reach, display a 404 page instead.
I have the files in the root folder:
content.php
about.php
footer.php
etc...
Now i can reach these files by typing in to the adress bar. I want to restrict this.
How can i do that?
A better approach that avoids the overhead and complexity of mod_rewrite is to simply not put files you don't want reached by url in the root folder. You can just put them somewhere else and include them from there; simple and (more) secure, but for some reason this doesn't seem to be common knowledge.
An example structure might be
project/
project/root
project/lib
Your public code (e.g. index.php) would live in project/root, and that would be the website root. Your included code would live in project/lib can be easily included using require, include, etc.
No mod_rewrite. Very simple.
RewriteRule \.php$ /path/to/page/404.html