Search code examples
.htaccessmod-rewriteurl-rewritingfriendly-url

htaccess rule giving 500 internal server error


I am getting errors when I am trying to rewrite URL.

From this:

www.example.com/products/product-details.php?alias=abc-def-123

To this:

www.example.com/products/abc-def-123

Here is my .htaccess file

#Turn Rewrite Engine On
Options +FollowSymLinks -MultiViews
Options -Indexes

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} ^www.example.com [NC]
RewriteRule ^(.*)$ https://example.com/$1 [L,R=301]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html [NC,L]

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

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^products/([a-zA-Z0-9-]+)$ products/product-details.php?alias=$1 [NC,L]

</IfModule>

I am hitting this URL:

www.example.com/products/abc-def-123

Update: enter image description here

enter image description here

enter image description here


Solution

  • Yeah!!!!!!! I solved my problem myself and also I want to thanks @RavinderSingh13 to make effort.

    Here is the whole .htaccess file

    <IfModule mod_rewrite.c>
    Options +FollowSymLinks -MultiViews -Indexes
    RewriteEngine On
    RewriteBase /
    
    RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
    RewriteRule ^(.*)/?$ https://example.com/$1 [L,NE,R=301]
    
    RewriteRule ^products/([^/\.]+)?$ products/product-details.php?alias=$1 [NC,L]  
    
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME}\.html -f [NC]
    RewriteRule ^(.*)/?$ $1.html [NC,L]
    
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME}\.php -f [NC]
    RewriteRule ^(.*)/?$ $1.php [NC,L]
    
    </IfModule>