How to remove id and title from this url?

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

Now the URL is 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 have already removed .php from all links.

+5
source share
4 answers

The 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 
+5
source

add below code to your .htaccess file.

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

conclusion

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

This code works for me, I hope it works for you.

+1
source

To access querystring, you need to use the RewriteCond statement as follows:

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

The above example works when the id and title parameters are in the exact order of your example. If the request may contain other parameters or if the parameters may be in any order, you will need to adjust the rules.

+1
source

Thank you very much for all these answers. Subod Ghulaxe posted a good answer.

But for me, this is working code.

 # To externally redirect /dir/foo.php?id=123&title=456 to /dir/123/456 RewriteCond %{THE_REQUEST} ^GET\s([^.]+)\.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} ^GET\s([^.]+)\.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} ^GET\s([^.]+)\.php\s [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 completed this code in here (full .htaccess code). I hope this code helps someone. For css, js, images necessarily use absolute paths.

+1
source

All Articles