I created a .htaccess file to set default index.html page to homepage.php only in root folder.
I already checked by adding DirectoryIndex homepage.php index.html, but this also work on all folders index pages.
Any body knows to sort this ?
Instead of DirectoryIndex use mod_rewrite rule in your site root .htaccess:
RewriteEngine On
RewriteRule ^(index\.html)?$ homepage.php [L,NX]
This will load homepage.php for landing page of your website.
Related
I have a specific website structure:
root:
styles.css
pages/index.html
folder_with_assets_1
folder_with_assets_2
folder_with_images
I've renamed index.html to index.php in order to get rid of .html extension in the URL
But the problem is that index.php is located not in a root folder, it's in pages folder.
Which right .htaccess rules could solve the problem in order to redirect requests to pages folder?
UPDATE
the screenshot with folder structure:
On the face of it, this just looks a standard front-controller pattern. Whether the front-controller is located inside a subdirectory or directly in the document root is largely irrelevant - the process is the same.
Assuming you are using the .htaccess file in the document root and there is no discernable pattern to the page URLs...
For example, using mod_dir FallbackResource:
FallbackResource /pages/index.php
Or, using mod_rewrite:
DirectoryIndex /pages/index.php
RewriteEngine On
RewriteRule (^|/)index\.php - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . pages/index.php [L]
UPDATE#1:
It's "onepage" website format with plenty of JS and CSS. There are only local URLs pointing to sections (href tag) and AJAX call to specific PHP files
In that case, it just looks like you need to change the DirectoryIndex - you don't need a front-controller pattern (as discussed above) at all.
For example:
DirectoryIndex /pages/index.php
Now, a request for the "homepage", ie the document root https://example.com/ will serve /pages/index.php.
UPDATE#2:
From your screenshot, it looks like directory listings (mod_autoindex) are enabled. These should be disabled at the top of the .htaccess file:
Options -Indexes
UPDATE#3:
From your screenshot, it would seem that what you have called "root" in your file structure is not actually your website's "document root", since you are accessing this location via a /test subdirectory, ie. localhost/test/. The directives above are assuming these files are located in the "document root", ie. localhost/ and there is no /test subdirectory. (Which I expect is how it is structured on your "live" environment?)
If your .htaccess file is located in the /test subdirectory and you are requesting localhost/test/ (as per your screenshot) then you will need to adjust this accordingly:
For example:
DirectoryIndex /test/pages/index.php
However, that will not work on the live site (assuming you don't have a /test subdirectory on live). Instead, you can simply omit the slash prefix, to make it relative.
For example:
DirectoryIndex pages/index.php
This should work OK in your case since you have a SPA (just a homepage URL).
can anyone please me How to hide subdirectory from url in php using htaccess without affecting index page of root directory
suppose i have url https://evidhya.com/KSTA-Webinar i want to hide KSTA-Webinar subdirectory from url but it should not affect index page of the https://evidhya.com and i just want to display in url https://evidhya.com/-KSTA-Webinar and here -KSTA-Webinar is title of the page
I tried myself and found the answer it is working perfectly for me.
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^-KSTA-Webinar/?$ KSTA-Webinar/-KSTA-Webinar [L,NC]
Do you mean you only want -KSTA-Webinar to redirect to the real folder KSTA-Webinar? If so, you can just change your <a href='...' values to include the -, then add this to your .htaccess file:
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^-KSTA-Webinar$ KSTA-Webinar/index.php [L]
...or whatever your file path is
We took over a website with about a kabillion pages in the old site root directory done in htm that need to be retired. I want to do a 301 redirect from the pages to the index.php in the root directory of the new site using a wildcard. An example of the page naming structure follows:
oldpage_dees.htm
oldPage_dat.htm
oldPage_deeudderting.htm
and so on. As stated, I need them redirected to the index.php in the root directory. Going by examples and discussions here I've tried:
RewriteEngine On
RewriteRule ^/oldpage_([\w]*).htm$ /index.php [R=301,L]
but I get a 404 error.
Any suggestions? Thanks in advance!
As .htaccess is directory level configuration file, you don't need to specify forward slash, I think this will do the job:
RewriteEngine On
RewriteRule ^oldpage_([\w]*).htm$ index.php [R=301,L]
Meanwhile, you can use the following .htaccess tester to debug your rewrite rules.
Hi i uploaded my website in below url : http://zendtest.com/
It shows file strucure in website. How to make public/index.php as default one.
File structure
public_html/
application
public
index.php
.htaccess
library
Anyone can help me ?
You have to define in Apache's httpd.conf DirectoryIndex. Like this:
<IfModule dir_module>
DirectoryIndex index.html index.php
</IfModule>
My site (grosvenorauctions.com) uses a modified Wordpress install to create a custom look - the blog part is driven by WP but other parts are outside WP. Consequently the index page for my site is not in the root folder but actually within the Wordpress folder. I am using htaccess (RedirectMatch ^/$ http://www.grosvenorauctions.com/wordpress/) to point to the index page in Wordpress but additionally I would like to hide the /wordpress/ part of the url. Is this possible? To be clear the htaccess file I have modified is in the root, not WP's own htaccess file.
Thanks
RewriteEngine On
RewriteBase /
RewriteRule ^/$ /wordpress/ [L]