skip to Main Content
Options -MultiViews

RewriteEngine on

Header set Strict-Transport-Security "max-age=31536000" env=HTTPS

Redirect /index https://example.com/

RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R] # <- for test, for prod use [L,R=301]

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

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

RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule !.*.php$ %{REQUEST_FILENAME}.php [QSA,L]

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9} /([^ ]+).php
RewriteRule ^/?(.*).php$ /$1 [L,R=301]

# Corporate Gifts
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^corporate-gifts/([^/]+)$ gift-category.php?slug=$1 [L]

# Services
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^services/([^/.]+)/?$ category.php?slug=$1 [L]
RewriteRule ^services/([^/.]+)/([^/.]+)$ sub-category.php?slug1=$1&slug=$2 [L]

#Uncomment the following lines as you create the pages.
#ErrorDocument 400 /400.php 
#Bad Request 

#ErrorDocument 401 /401.php
#Unautorized

#ErrorDocument 403 /403.php
#Forbidden

ErrorDocument 404 https://example.com/404.php
#Not Found

#ErrorDocument 500 /500.php
#Internal Server Error

# php -- BEGIN cPanel-generated handler, do not edit
# Set the “ea-php80” package as the default “PHP” programming language.
<IfModule mime_module>
  AddHandler application/x-httpd-ea-php80___lsphp .php .php8 .phtml
</IfModule>
# php -- END cPanel-generated handler, do not edit
 

On our website there are two types of categories, "services" and the second is corporate gifts. for the service category page, I add the rewrite rule as above the .htaccess code. Our service page menu is like that (Service -> Uniform -> School Uniform) dynamic value comes from the admin side. for the second tab menu corporate gifts we create one .php page named corporate-gifts.php.

I need corporate gift page menu like that (Corporate Gifts -> Apparel -> Badges). When we click on the page corporate gifts its work fine but when I click on apparel page in subcategory then corporate gifts main category page open rather then sub category. how to apply .htaccess rule for different category in menu bar.

I try above .htaccess code i need a solution for conflict problem.

2

Answers


  1. Chosen as BEST ANSWER
    Options -MultiViews
    
    RewriteEngine on
    
    Header set Strict-Transport-Security "max-age=31536000" env=HTTPS
    
    Redirect /index https://example.com/
    
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)/$ /$1 [L,R] # <- for test, for prod use [L,R=301]
    
    RewriteCond %{HTTP_HOST} ^www.(.*)$ [NC]
    RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
    
    RewriteCond %{HTTP_HOST} https://example.com/$ [NC] 
    RewriteRule (.*) https://example.com/$1 [R=301,L]
    
    # Corporate Gifts
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteRule ^corporate-gifts/([^/]+)$ gift-category.php?slug=$1 [QSA,L]
    
    # Services
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^services/([^/.]+)/?$ category.php?slug=$1 [L]
    RewriteRule ^services/([^/.]+)/([^/.]+)$ sub-category.php?slug1=$1&slug=$2 [L]
    
    RewriteCond %{REQUEST_FILENAME}.php -f
    RewriteRule !.*.php$ %{REQUEST_FILENAME}.php [QSA,L]
    
    RewriteCond %{THE_REQUEST} ^[A-Z]{3,9} /([^ ]+).php
    RewriteRule ^/?(.*).php$ /$1 [L,R=301]
    
    #Uncomment the following lines as you create the pages.
    #ErrorDocument 400 /400.php 
    #Bad Request 
    
    #ErrorDocument 401 /401.php
    #Unautorized
    
    #ErrorDocument 403 /403.php
    #Forbidden
    
    ErrorDocument 404 https://example.com/404.php
    #Not Found
    
    #ErrorDocument 500 /500.php
    #Internal Server Error
    
    # php -- BEGIN cPanel-generated handler, do not edit
    # Set the “ea-php80” package as the default “PHP” programming language.
    <IfModule mime_module>
      AddHandler application/x-httpd-ea-php80___lsphp .php .php8 .phtml
    </IfModule>
    # php -- END cPanel-generated handler, do not edit
    

    I post my answer for correct method. i change the rule position of my code and now its working fine without conflict problem.


  2. You can resolve this issue by making your rules more specific and ensuring they don’t overlap :

    RewriteEngine On
    
    # Corporate Gifts
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^corporate-gifts/([^/]+)$ gift-category.php?slug=$1 [L]
    
    # Services
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^services/([^/.]+)/?$ category.php?slug=$1 [L]
    RewriteRule ^services/([^/.]+)/([^/.]+)$ sub-category.php?slug1=$1&slug=$2 [L]
    

    Test

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search