skip to Main Content

I need to remove ?id= and &title= from this url using .htaccess file.

URL now – http://www.XXXX.com/video.php?id=XX&title=XXX-XXX-XXX

What I need – http://www.XXXX.com/video.php/XX/XXX-XXX-XXX

I already have removed .php from all links.

4

Answers


  1. Chosen as BEST ANSWER

    Thanks you so much for all this answers.Subodh Ghulaxe have posted a good answer.

    But this is working code for me.

    # To externally redirect /dir/foo.php?id=123&title=456 to /dir/123/456
    RewriteCond %{THE_REQUEST} ^GETs([^.]+).php?id=([^&]+)&title=([^&s]+) [NC]
    RewriteRule ^ %1/%2/%3? [R,L]
    
    # To externally redirect /dir/foo.php?id=123 to /dir/123
    RewriteCond %{THE_REQUEST} ^GETs([^.]+).php?id=([^&s]+)s [NC]
    RewriteRule ^ %1/%2? [R,L]
    
    # To internally forward /dir/foo/12 to /dir/foo.php?id=12
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME}.php -f
    RewriteRule ^(.+?)/([^/]+)(/[^/]+)?/?$ $1.php?id=$2 [L,QSA]
    
    RewriteRule ^([a-zA-Z0-9_-]+)/([0-9]+)$ video.php?id=$1&title=$2
    RewriteRule ^([a-zA-Z0-9_-]+)/([0-9]+)/$ video.php?id=$1&title=$2
    
    # To externally redirect /dir/foo.php to /dir/foo
    RewriteCond %{THE_REQUEST} ^GETs([^.]+).phps [NC]
    RewriteRule ^ %1 [R,L]
    
    # To internally forward /dir/foo to /dir/foo.php
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME}.php -f
    RewriteCond %{QUERY_STRING} ^$
    RewriteRule ^(.*?)/?$ $1.php [L]
    

    Sumurai8 finished this code in here ( complete .htaccess code ). I hope this code will help to someone.For css, js, images make sure to use absolute paths.


  2. Following htaccess code will do your work

        //First Parameer
        RewriteEngine On
        RewriteRule ^([a-zA-Z0-9_-]+)$ video.php?id=$1
        RewriteRule ^([a-zA-Z0-9_-]+)/$ video.php?id=$1
    
        //Second Parameter
        RewriteEngine On
        RewriteRule ^([a-zA-Z0-9_-]+)/([0-9]+)$ video.php?id=$1&title=$2
        RewriteRule ^([a-zA-Z0-9_-]+)/([0-9]+)/$ video.php?id=$1&title=$2
    
    Login or Signup to reply.
  3. add below code to your .htaccess file.

    RewriteEngine on
    RewriteBase / 
    RewriteCond %{QUERY_STRING} ^id=(.*)&title=(.*)
    RewriteRule (.*) /$1/%1/%2?  [NC,L,R=301]
    

    output is

    http://www.XXXX.com/video.php/XX/XXX-XXX-XXX
    

    this code is working for me i hope it is working for you.

    Login or Signup to reply.
  4. In order to access the querystring you need to use a RewriteCond statement like this:

    RewriteEngine on
    RewriteCond %{QUERY_STRING} id=([^&]+)&title=([^&]+)
    RewriteRule ^video.php$ video.php/%1/%2 [L,R=301]
    

    The above example works when id and title parameters are in the exact order of your example. If there can be other parameters in the querystring, or if the parameters can be in any order, you would need to adjust the rules.

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