skip to Main Content

I am trying to get an improvised SEO via cleaner URL.
Below is my .htaccess file:

<IfModule mod_rewrite.c>
  RewriteEngine on
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^ cleanurl2/podtadquery.php [L]
</IfModule>

Below is what my url is currently looking like:

http://localhost/cleanerurl2/podtadquery.php?product=Actuators&subgroup=Electrical

What I am trying to achieve is

http://localhost/cleanerurl2/podtadquery.php/Actuators/Electrical

Please suggest how can I achieve this. Thanks in adance

2

Answers


  1. You can use the following code in /root/.htaccess

    RewriteEngine On
    #1)
    #Redirect from "/cleanerurl2/podtadquery.php?product=foo&subgroup=bar" to "/cleanerurl2/podtadquery.php/foo/bar"
    RewriteCond %{THE_REQUEST} /cleanerurl2/podtadquery.php?product=([^&]+)&subgroup=([^&s]+) [NC]
    RewriteRule ^ /cleanerurl2/podtadquery.php/%1/%2? [NC,L,R]
    #2)
    #Now, internally redirect "/cleanerurl2/podtadquery.php/foo/bar" to "/cleanerurl2/podtadquery.php?product=foo&subgroup=bar
    RewriteRule ^cleanerurl2/podtadquery.php/([^/]+)/([^/]+)/?$ /cleanerurl2/podtadquery.php?product=$1&subgroup=$2 [NC,L]
    
    Login or Signup to reply.
  2. In your .htaccess file

    RewriteEngine On
    RewriteRule !.(?:jpe?g|gif|bmp|png|tiff|css|js)$ index.php [L,NC]
    

    Second line is to exclude jpg,jpeg,gif,bmp,png,tiff,css and js file. Other uri will be forwarded to index.php.

    in index.php

    <?php
    $uri = rtrim( dirname($_SERVER["SCRIPT_NAME"]), '/' );
    $uri = trim( str_replace( $uri, '', $_SERVER['REQUEST_URI'] ), '/' );
    
    echo $uri;
    ?>
    

    If you are using ubuntu server, please do below lines too

    Step 1.

    sudo a2enmod rewrite
    

    Step 2.
    Open apache conf file

    sudo vim /etc/apache2/apache2.conf
    

    Uncomment this line(about 187th line approx)

    AccessFileName .htaccess
    

    Then find the line where there is

    <Directory /var/www/>
             Options Indexes FollowSymLinks
             AllowOverride None
             Require all granted
    </Directory>
    

    replace “None” with “All”

    <Directory /var/www/>
             Options Indexes FollowSymLinks
             AllowOverride All
             Require all granted
    </Directory>
    

    Step 3.
    Restart apache

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