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.
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.
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
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.
/video.php
–
Workman 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.
RewriteRule ^video.php$
matches just /video.php
nothing else. –
Workman 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} ^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 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.
© 2022 - 2024 — McMap. All rights reserved.
RewriteRule ^video/([0-9]+)/([0-9a-zA-Z_-]+)$ video.php?id=$1&title=$2 [NC,L]
this is not working.. – Ethics