I have an url which is http://www.urlbookmarking.com/bookmarks-details.php?bid=55 and I want it to be like http://www.urlbookmarking.com/bookmark/55
I wrote in my htaccess:
RewriteEngine on
RewriteRule /bid/(.*) bookmarks-details.php?bid=$1
But when I go to the first URL the rewrite engine does not apply my rule. Is there any mistake, or conflict somewhere?
My full htaccess file written as follows
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
RewriteEngine on
RewriteCond %{HTTP_HOST} ^urlbookmarking.com [NC]
RewriteRule ^(.*)$ http://www.urlbookmarking.com/$1 [L,R=301]
RewriteEngine on
RewriteRule /bid/(.*) bookmarks-details.php?bid=$1
Please help me.
This should redirect all '/bookmarks-details.php\?bid=(id)' urls with bookmarks ids (that have only numbers) to /bookmark/(id).
Once you successfully rewritten the URL, you then need to write a companion rule to process it, like so:
If should go between the rule that always adds 'www' to the beginning and the catch all rule, which I placed at the end. All together, it may look like so:
This link may make things clearer: http://corz.org/serv/tricks/htaccess2.php
Do you want you url to be
/bid/55
or/bookmark/55
? because you have written it as if it is going to be/bid/55
...Anyway, your .htaccess should look more like this:
...without the multiple
RewriteEngine on
directives (these don't break anything but are unnecessary), and without the leading forward slash on thebid
rewrite rule. Also, put your new rule before the rules that rewrites for non-existent file so it doesn't rewrite your URL before you get a chance to use it, and add a[L]
flag to the rule so it doesn't get further modified by the other rules. Also, add the line start/end markers (^
/$
) to the rule.You would only use the leading forward slash if you were putting the rules in
httpd.conf
, you don't use them in.htaccess
files.If you want your urls to be
/bookmark/
, just replacebid
withbookmark
.The line
Options +FollowSymLinks
is optional if already configured in httpd.confRewriteEngine on
RewriteRule /bid/(.*) bookmarks-details.php?bid=$1
- put this line afterOptions +FollowSymLinks
A few things:
RewriteEngine On
only needs to called once, though this may not be causing any problemsRewriteBase /
after myRewriteEngine On
lineRewriteRule ^common/(.*)$ common.php?file=$1 [QSA,L]
, which tells me that your rule should looke like thisRewriteRule ^bookmark/(.*) bookmarks-details.php?bid=$1 [QSA,L]