2 votes

Je ne peux pas changer la page d'accueil de mon site de streaming.

Je essaie de changer la page d'accueil de mon site mais rien ne se passe. Lorsque je saisis le code ci-dessous "DirectoryIndex index.html #pour faire de index.html la page d'accueil" ma page d'accueil reste la même. Je fais des modifications dans le fichier .htaccess

    Options +FollowSymlinks
    RewriteEngine On

    # Désactiver explicitement la réécriture pour les contrôleurs frontaux
    RewriteRule ^index.php - [L]
    RewriteRule ^index.php - [L]

    RewriteCond %{REQUEST_FILENAME} !-f

    # Changer ci-dessous avant le déploiement en production
    #RewriteRule ^(.*)$ index.php [QSA,L]
    RewriteRule ^(.*)$ index.php [QSA,L]

DirectoryIndex index.html #pour faire de index.html la page d'accueil

Mon site web est écrit en php et je veux mettre la page d'accueil en html

1voto

w3d Points 3138
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 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.

Prograide.com

Prograide est une communauté de développeurs qui cherche à élargir la connaissance de la programmation au-delà de l'anglais.
Pour cela nous avons les plus grands doutes résolus en français et vous pouvez aussi poser vos propres questions ou résoudre celles des autres.

Powered by:

X