ohdang888 Posted June 18, 2009 Share Posted June 18, 2009 When someone types in www.mydomain.com/a3kd .... i want it to go to photo.php?id=a3kd But when someone types in www.mydomain.com/contact i want it to go to the contact folder, index.php So, i have this rule: RewriteEngine on RewriteRule ^(.*+)$ photo.php?id=$1 BUT, that redirects the www.mydomain.com/contact to photo.php?id=contact. Any ideas? Oh ya, and the "id" may be between 4 and 10 characters long Thanks! Link to comment https://forums.phpfreaks.com/topic/162818-mod-rewrite/ Share on other sites More sharing options...
Daniel0 Posted June 18, 2009 Share Posted June 18, 2009 Add RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d before the RewriteRule. Link to comment https://forums.phpfreaks.com/topic/162818-mod-rewrite/#findComment-859188 Share on other sites More sharing options...
ohdang888 Posted June 18, 2009 Author Share Posted June 18, 2009 Add RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d before the RewriteRule. thanks!! Link to comment https://forums.phpfreaks.com/topic/162818-mod-rewrite/#findComment-859191 Share on other sites More sharing options...
ohdang888 Posted June 18, 2009 Author Share Posted June 18, 2009 one more question. how does mod rewrite decide which one of the following to use in the case of: www.mydomain.com/test/154534 RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*+)$ index.php?id=$1 RewriteRule ^test/(.*+)$ testing1234.php?id=$1 b/c right now, its directing that url to index.php even though i declare "test" in it. Link to comment https://forums.phpfreaks.com/topic/162818-mod-rewrite/#findComment-859194 Share on other sites More sharing options...
Daniel0 Posted June 18, 2009 Share Posted June 18, 2009 It matches as long as it can and as long as you don't stop the chain. So www.mydomain.com/test/154534 matches the first rule, and it becomes www.mydomain.com/index.php?id=test/154534, which doesn't match any further rules. You can switch the rules around and add [L] to the one with "test", or you can limit the regex in the current first one. Link to comment https://forums.phpfreaks.com/topic/162818-mod-rewrite/#findComment-859199 Share on other sites More sharing options...
ohdang888 Posted June 18, 2009 Author Share Posted June 18, 2009 ohhh ok that makes sense. thanks. Link to comment https://forums.phpfreaks.com/topic/162818-mod-rewrite/#findComment-859201 Share on other sites More sharing options...
ohdang888 Posted June 18, 2009 Author Share Posted June 18, 2009 I have this: RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^test/(.*+)$ testing1234.php?id=$1 [L] RewriteRule ^(.*+)$ index.php?id=$1 and this url: http://smydomain.com/test/3546 and its still using index.php Link to comment https://forums.phpfreaks.com/topic/162818-mod-rewrite/#findComment-859211 Share on other sites More sharing options...
Ken2k7 Posted June 20, 2009 Share Posted June 20, 2009 Try adding - RewriteBase / Link to comment https://forums.phpfreaks.com/topic/162818-mod-rewrite/#findComment-860047 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.