I am trying to use mod_rewrite for my urls. Here is my .htaccess file. Options +Indexes Options +FollowSymlinks RewriteEngine on RewriteBase / RewriteRule ^(.*)\.html$ itmes.php?id=$1 [L] RewriteRule ^(.*)/(.*)\.html$ description.php?id=$1& category=2 [L] My problem is… when I use for both url, only first url works 2nd url does not. But both url works independently. I don't get any error either. I plan to use more mod_rewrite urls, what am I doing wrong here? Do I need to change anything?
Hi. I'm no expert but it could be this. [L] That L indicates that it is the last rule in the list. So the server stops at your first command. Other than that, I'm not sure so I hope someone more experienced comes by. Good luck.
There fighting over each other. No, this is an items page....er no, description page...NOOOO.... Options +Indexes Options +FollowSymlinks RewriteEngine on RewriteBase / RewriteRule ^description/([^.]+)/([^.]+)\.html$ description.php?id=$1& category=2 [L] RewriteRule ^items/([^.]+)\.html$ itmes.php?id=$1 [L] If it's an items page, itmes.php and the actual script file should probably be changed to items.php just so it's spelled correctly!
the (.*)\.html in your first rule matches *anything*, including if it contains a forward slash. Try reversing the 2 rules Options +Indexes Options +FollowSymlinks RewriteEngine on RewriteBase / # This will match anything slash anything, and if it doesn't match # will continue on to the second rule RewriteRule ^(.*)/(.*)\.html$ description.php?id=$1& category=2 [L] RewriteRule ^(.*)\.html$ itmes.php?id=$1 [L] Code (markup): Also, it looks like you have the $1 and $2 mixed up- I would assume the category would be the "directory" and the id would be the "filename". RewriteRule ^(.*)/(.*)\.html$ description.php?id=$2& category=$1 [L] Code (markup):
Note exam's post on the order, if you want the category part before the item in the URL. Just change 1 to 2 and 2 to 1. And & category= shouldn't have that space.
I should figure out by myself but I could not. How would I write mod_rewrite if I don’t want to use folder type system. For example: Instead of using: www.mysite.com/category.html < ----- one query string www.mysite.com/category/itemtype1.html < ----- two query strings www.mysite/category/itemtype2.html < ----- two query strings www.mysite.com/category/itemtype3.html < ----- two query strings I want to use this: www.mysite.com/category.html < ----- one query string www.mysite.com/category-itemtype1.html < ----- two query strings www.mysite.com/category-itemtype2.html < ----- two query strings www.mysite.com/category-itemtype3.html < ----- two query strings I hope you understand my question. Let me know if you need further clarification. I hope you understand my question. Let me know if you need further clarification.
Change each / to \- Three of them. If the only change is going from 'directory' to looking like a .html file with -.