I’ve got a directory called fb and a script inside called like.php. I’d like to have the get-id passed to the like-file using mod_rewrite.
mypage.com/fb/like.php?id=5 would be mypage.com/fb/like/5
My (not working) htaccess looks like this:
RewriteEngine on
RewriteRule /fb/like/([0-9]+) /fb/like.php?id=$1
Does anyone see what’s wrong here?
Try removing the slash at the beginning of your match and replace patterns like so:
mypage.com/is the domain name, so the string that gets matched isfb/like/5Also consider using the carat at the start of your match string so that it will match
fbbut notfffb:Here’s a short guide to mod_rewrite I’ve found helpful.
Edit for your follow-up question:
To match mypage.com/something/fb/like/5, you can do this:
This saves the first directory as $1.
[^/]+means match one or more characters that are not a slash. Put this .htaccess file in the root directory of your domain.Alternatively, you can use the second-to-last rule and put that .htaccess file in the “something” subdirectory. Hope that makes sense.
Or you can write a rule to match simply
like.php/([0-9]+)so that it’ll work no matter what the directory path looks like. You can go even more generic and make this apply to any PHP file, not justlike.php. It really depends on how you want your site to work.