Home > Back-end >  I can't change my streaming website homepage
I can't change my streaming website homepage

Time:03-23

I'm trying to change the homepage of my site but nothing is happening. When entering the code below "DirectoryIndex index.html #to make index.html as index" my home page remains the same. I'm making changes to the file in .htaccess

<IfModule mod_rewrite.c>
    Options  FollowSymlinks
    RewriteEngine On

    # Explicitly disable rewriting for front controllers
    RewriteRule ^index.php - [L]
    RewriteRule ^index.php - [L]

    RewriteCond %{REQUEST_FILENAME} !-f

    # Change below before deploying to production
    #RewriteRule ^(.*)$ index.php [QSA,L]
    RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>

DirectoryIndex index.html #to make index.html as index

My website is written in php and I want to put the homepage in html

CodePudding user response:

RewriteRule ^(.*)$ index.php [QSA,L]

Change the * quantifier to , so that it only matches non-empty URL-paths, to allow the DirectoryIndex document (ie. index.html) to be served for requests to the homepage, instead of passing the request through to the front-controller (ie. index.php). Or, simply use a dot (.) as the regex since you aren't doing anything with the captured URL-path. For example:

RewriteRule . index.php [L]

(The QSA flag is not required here.)

Although, since you are using a front-controller pattern (ie. routing all requests to index.php), you should probably be configuring the appropriate response to be served from index.php instead?


Aside:

DirectoryIndex index.html #to make index.html as index

You should remove, what you think is a comment at the end of the line, ie. "#to make index.html as index". That's not actually a comment. Apache does not support line-end comments (only full-line comments are supported). In this instance, #to, make, index.html, as and index will be seen as additional arguments to the DirectoryIndex directive (so you don't actually get an error).

See my answer to the following question regarding the use of line-end comments:
Error 500: .htaccess RewriteCond: bad flag delimiters


UPDATE:

Alternative solution

Try the following instead (this replaces the entire .htaccess file above):

Options  FollowSymlinks
RewriteEngine On

# Explicitly disable rewriting for front controllers
RewriteRule ^index\.(php|html)$ - [L]

# Rewrite any request for anything that is not a file to "index.php"
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . index.php [L]

# Rewrite the homepage only to "index.html"
RewriteRule ^$ index.html [L]

The <IfModule> wrapper is not required. (This is your server so you know if mod_rewrite is enabled or not and these directives are not optional.)

Make sure you've cleared your browser cache before testing.

  • Related