sunena
sunena

Reputation: 81

how to change htaccess rule to make url with query string without trailing slash

I want to change some rules in .htaccess file write now my url is like this www.example.com/d/somthing.htm and some another pages with www.example.com/category.htm now i want to change them in this way www.example.com/index.php?d=somthing what i have to do.

My current .htaccess content are:-

 <IfModule mod_rewrite.c>
    Options +FollowSymLinks
    RewriteEngine On
    RewriteBase /

    #RewriteCond %{REQUEST_FILENAME} !-f
    #RewriteCond %{REQUEST_FILENAME} !-d
    #RewriteCond %{REQUEST_URI} ^/p\/[a-z][a-z]\/[[:print:]]+\.htm$
    #RewriteRule \/p\/([a-z][a-z])\/([[:print:]]+)\.htm$ /index.php?p=$2&lang=$1 [L]
    #RewriteRule \/p\/([a-z][a-z])\/([[:print:]]+)\.htm$ /index.php?p=$2&lang=$1 [L]

    RewriteRule . /index.php [L]

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} ^/p\/[[:print:]]+\.htm$
    RewriteRule \/p\/([[:print:]]+)\.htm$ /index.php?p=$1 [L]



    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} ^/s\/[a-z][a-z]\/[0-9]+\/.*$
    RewriteRule \/s\/([a-z][a-z])\/([0-9]+)\/.*$ /category.php?action=something&value=$2&lang=$1 [L]

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} ^/s\/[0-9]+\/.*$
    RewriteRule \/s\/([0-9]+)\/.*$ /category.php?action=something&value=$1 [L]

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} ^/n\/[a-z][a-z]\/[0-9]+\/.*$
    RewriteRule \/n\/([a-z][a-z])\/([0-9]+)\/.*$ /novel.php?action=more&value=$2&lang=$1 [L]

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} ^\/n\/[0-9]+\/.*$
    RewriteRule \/n\/([0-9]+)\/.*$ /novel.php?action=more&value=$1 [L]

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} ^\/sn\/[0-9]+\/.*$
    RewriteRule \/sn\/([0-9]+)\/.*$ /novel.php?action=all&type=$1 [L]

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} ^\/[a-z][a-z]\/[0-9]+\/.*$
    RewriteRule \/([a-z][a-z])\/([0-9]+)\/.*$ /category.php?action=product&product=$2&lang=$1 [L]

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} ^\/[0-9]+\/.*$
    RewriteRule \/([0-9]+)\/.*$ /category.php?action=product&product=$1 [L]

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} ^\/img\/[0-9]+\/[0-9]+\/.*$
    RewriteRule \/img\/([0-9]+)\/([0-9]+)\/.*$ /img.php?value=$1-$2 [L]

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} ^/[0-9]+\+[a-z][a-z]\+[0-9]+\+.*$
    RewriteRule /([0-9]+)\+([a-z][a-z])\+([0-9]+)\+.*$ /category.php?action=product&product=$1&lang=$2&something=$3 [L]

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} ^/[0-9]+\+[a-z][a-z]\+.*$
    RewriteRule /([0-9]+)\+([a-z][a-z])\+.*$ /category.php?action=product&product=$1&lang=$2 [L]

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} ^/[0-9]+\+\+.*$
    RewriteRule /([0-9]+)\+\+.*$ /category.php?action=product&product=$1 [L]

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} ^\/img\/[0-9]+\/[0-9]+\/.*$
    RewriteRule \/img\/([0-9]+)\/([0-9]+)\/.*$ /img.php?value=$1-$2 [L]

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} ^/[0-9]+\+[a-z][a-z]\+[0-9]+\+.*$
    RewriteRule /([0-9]+)\+([a-z][a-z])\+([0-9]+)\+.*$ /category.php?action=product&product=$1&lang=$2&something=$3 [L]

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} ^/[0-9]+\+[a-z][a-z]\+.*$
    RewriteRule /([0-9]+)\+([a-z][a-z])\+.*$ /category.php?action=product&product=$1&lang=$2 [L]

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} ^/[0-9]+\+\+.*$
    RewriteRule /([0-9]+)\+\+.*$ /category.php?action=product&product=$1 [L]

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} ^/[0-9]+$
    RewriteRule /([0-9]+)$ /category.php?action=product&product=$1 [L]

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} ^/s[0-9]+\+[a-z][a-z]\+.*$
    RewriteRule /s([0-9]+)\+([a-z][a-z])\+.*$ /category.php?action=something&value=$1&lang=$2 [L]



</IfModule>

Upvotes: 1

Views: 259

Answers (1)

anubhava
anubhava

Reputation: 785531

You can use these 2 rules in your root .htaccess:

DirectoryIndex index.php

RewriteEngine On

RewriteRule ^(?:d/)?(.+?)\.html?$ index.php?d=$1 [L,QSA,NC,R]

Upvotes: 2

Related Questions