Forum Topic: Remove ?id queries from url
I’m currently running a website, that has one of the url’s this way..
http://example.com/browse.php?id=3456/AnimaliaKingdom.html
I’m trying to make the url’s look just like this
http://example.com/browse/3456/AnimaliaKingdom.html
or
http://example.com/browse/AnimaliaKingdom-3456.html
In my .php
file, I’m using this location at header
header("Location: browse.php?id=$id/$row[name].html");
I’ve used the below code in htacess file but it doesn’t seem to work, I can’t tell if its working but my location is making it not work.
RewriteEngine On
RewriteRule ^browse/id/([^/]*)$ /browse.php?id=$1 [L]
RewriteEngine On
RewriteRule ^/api/([^/]*) /api.php?category=$1 [L]
AddType text/x-component .htc
RewriteEngine On
RewriteBase /
# remove .php; use THE_REQUEST to prevent infinite loops
RewriteCond %{THE_REQUEST} ^GET\ (.*)\.php\ HTTP
RewriteRule (.*)\.php$ $1 [R=301]
# remove index
RewriteRule (.*)/index$ $1/ [R=301]
# remove slash if not directory
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} /$
RewriteRule (.*)/ $1 [R=301]
# add .php to access file, but don't redirect
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteCond %{REQUEST_URI} !/$
RewriteRule (.*) $1\.php [L]
3 Replies to “Remove ?id queries from url”
Using all of that code should not be necessary for a simple redirect. Something like this should work:
RewriteCond %{REQUEST_URI} ^/browse.php [NC]
RewriteCond %{QUERY_STRING} ^id=(.*)/(.*)\.(.*) [NC,OR]
RewriteRule .* http://example.com/browse/%1/%2.%3 [L,R=301]
Of course, before even trying this, any/all other redirect codes should be removed so they don’t interfere.
http://example.com/browse//?id=16916/Free%252525252525252525252525252525252525252520Birds%2525252525252525252525252525252525252525202013%252525252525252525252525252525252525252520DVDRip%252525252525252525252525252525252525252520x264-COCAIN
this was the result and the error message was
Firefox has detected that the server is redirecting the request for this address in a way that will never complete.
do you think the header
header("Location: browse.php?id=$id/$row[name].html");
Is interfering with this..
Do I need to change anything in my code.. ?
Yes, like I said: “Of course, before even trying this, any/all other redirect codes should be removed so they don’t interfere.” So I would make a backup of any file that you plan on editing, and then try my suggestion. If it does not work, then simply restore original functionality by replacing the backup file(s). Good luck.