How to fix htaccess file is not working on Cpanel

2 replies
actually am trying to make seo friendly url's with htaccess but my htaccess file is not working in cpanel. this code is working fine in localhost that's my code for htaccess file

#Remove .php extension
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php [NC,L]

RewriteEngine On

RewriteRule ^projects/([^/\.]+)/?$ project-detail?p=$1
RewriteRule ^category/([0-9a-zA-z]+)/?$ category-detail?c=$1

RewriteRule ^post/([^/\.]+)/?$ post-detail?p=$1

how can i fix this ?
#cpanel #file #fix #htaccess #working
  • Profile picture of the author patrick21
    Try it like this instead:

    Options -MultiViews

    RewriteEngine on

    RewriteRule ^projects/([^/.]+)/?$ project-detail.php?p=$1 [L]
    RewriteRule ^category/([0-9a-zA-z]+)/?$ category-detail.php?c=$1 [L]
    RewriteRule ^post/([^/.]+)/?$ post-detail.php?p=$1 [L]

    RewriteCond %{DOCUMENT_ROOT}/$1.php -f
    RewriteRule ^([^.]+)$ $1.php [L]
    (Although post-detail.php does not seem to exist on your site.)
    {{ DiscussionBoard.errors[11742606].message }}
  • Profile picture of the author Emma0512
    If your .htaccess file is not working on cPanel, you can try the following steps to resolve the issue:

    1 - Check the syntax: Make sure your .htaccess file has the correct syntax and there are no errors in it.

    Ensure .htaccess is allowed: cPanel may have an option to disable .htaccess files, check if this option is enabled for your account.

    Verify mod_rewrite is enabled: mod_rewrite is required for .htaccess files to work. You can check if it's enabled by creating a PHP file with the following code and accessing it through your browser:

    <?php
    phpinfo();
    ?>

    Search for mod_rewrite in the output, it should be enabled.

    4 - Restart Apache: Restarting Apache may also resolve the issue.

    Contact your host: If none of the above steps work, you can contact your host and ask for assistance.

    If the issue persists, it's best to consult with a developer or a server administrator to diagnose the problem further.
    {{ DiscussionBoard.errors[11743634].message }}

Trending Topics