Rommeo Posted November 30, 2009 Share Posted November 30, 2009 There are just 3 lines of code not working with in my htaccess file 1-) One section uses links like mysite.com/34/hello+world here I do not do any process with hello world part, it goes to mysite.com/index.php?pageid=34 I was trying to use this code which is not working RewriteRule ^p([a-zA-Z0-9-_]+)/?$ index.php?pageid=$1 2-) Same as one but this time I m using both: like mysite.com/12/my+category should go to mysite.com/index.php?cat=12&subcategory=my+category I tried to use this one which is not working again RewriteRule ^([a-zA-Z0-9_]+)/([-A-Za-z0-9_]+)/?$ index.php?cat=$1&subcategory=$2 3-) This one I m using for photos which is not working also : mysite.com/i/12-1 should go to mysite.com/showphoto.php?id=12-1 RewriteRule ^i/([a-zA-Z0-9-_]+)/?$ showphoto.php?id=$1 Also I m wondering if the declarations are correct ? cause I m using special characters like "+" and "-". Can someone please help me to solve this problem ? Thank you in advance. How can I declare "+" sign in my codes. Cause I m using "+" and I m wondering if plus sign is not declared in my codes. Quote Link to comment Share on other sites More sharing options...
cags Posted November 30, 2009 Share Posted November 30, 2009 1 and 2 are mutually exclusive, you can't possible have a site that supports both objectives. Just look at the two example URLs... mysite.com/34/hello+world mysite.com/12/my+category They use the EXACT same format, how is Apache supposed to know the first one is a page and the second is a category? Moving on to look at the actually code you provided for 1-). RewriteRule ^p([a-zA-Z0-9-_]+)/?$ index.php?pageid=$1 This assumes that the URL begins with a p, which it doesn't. It's actually beginning with a number. It would also (assuming it worked) forward the whole end of the URL (34/hello+world). As for 2-), that pattern looks alot more 'correct'. You will need to add + to the character class though, since you are seperating your words with +'s. RewriteRule ^([a-zA-Z0-9_+]+)/([-A-Za-z0-9_+]+)/?$ index.php?cat=$1&subcategory=$2 With 3-) I'd recomend putting the dash as the last character in the characterset (ie before the underscore) or at the start as in the other pattern. Since it is a Regular Expression metacharacter having it where you have it could potentially cause problems. RewriteRule ^i/([a-zA-Z0-9_-]+)/?$ showphoto.php?id=$1 Quote Link to comment Share on other sites More sharing options...
Rommeo Posted November 30, 2009 Author Share Posted November 30, 2009 Thank you for the explanation. At first I tried the second code and I disabled the same kind of codes. It works. . But the problem is it's without any design. I mean just text. My images, css, tables are lost. It's like a text in notepad. Why it's it so ? ( also tried it while others are enabled, it's same pure text. ) And for the third one can you give me any example please ? should I use the images like ? mysite.com/i/12-1- Quote Link to comment Share on other sites More sharing options...
cags Posted November 30, 2009 Share Posted November 30, 2009 Do you have a live example? I'd imagine it's going to be due to relative links. Quote Link to comment Share on other sites More sharing options...
Rommeo Posted November 30, 2009 Author Share Posted November 30, 2009 I m working on my try-out server Can tell you if you want to know anything I m wondering if the code should supply the exact needs. like : RewriteRule ^([0-9]+)/([A-Za-z+]+)/?$ index.php?cat=$1&subcategory=$2 The first part will be just numbers. So this might be correct if I m not wrong ? Quote Link to comment Share on other sites More sharing options...
cags Posted November 30, 2009 Share Posted November 30, 2009 Assuming the the pattern is always similar to the example URLs ie a number followed by a forward slash followed by the characters a-z or +, that would be fine. The reason for images etc not working is probably because when the browser requests them your pattern is matching them. Matching your pattern more precisely in the manner you have done will help with this, you will also want to use Rewrite Conditions. For example something like... RewriteCond %{SCRIPT_FILENAME} !-d RewriteCond %{SCRIPT_FILENAME} !-f RewriteRule ^([0-9]+)/([A-Za-z+]+)/?$ index.php?cat=$1&subcategory=$2 That basically will only forward the URL if the requested file/directory doesn't exist. Quote Link to comment Share on other sites More sharing options...
Rommeo Posted November 30, 2009 Author Share Posted November 30, 2009 Yes my problem is solved ! Thank you so much. The codes you wrote are worked well. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.