subhomoy Posted August 20, 2014 Share Posted August 20, 2014 Hello every body Currently I'm facing a new prbel with .htaccess. I've used this code to remove the .php extention and add a trailing '/' at the end. RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^([^/]+)/$ $1.php RewriteRule ^([^/]+)/([^/]+)/$ /$1/$2.php RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$ RewriteRule (.*)$ /$1/ [R=301,L] RewriteCond %{HTTP_HOST} !^www.superioradsmedia.com$ [NC] RewriteRule ^(.*)$ http://www.superioradsmedia.com/$1 [L,R=301] Everything is working fine except two things 1) If I use an image location like "www.abc.com/images/abc.jpg" it does'nt show up.. But if I use 'http://' in front of it it shows the image... 2) Suppose I have a directory in my root directory like 'new_folder' which contains an index.php page If i access like this www.abc.com/new_folder -------------------> It gives me 404 error... But if I use www.abc.com/new_folder/index.php ---------------------> it works... ANy help will be greatly appreciated.... Thank you... Quote Link to comment https://forums.phpfreaks.com/topic/290561-htaccess-problem/ Share on other sites More sharing options...
requinix Posted August 20, 2014 Share Posted August 20, 2014 1) If I use an image location like "www.abc.com/images/abc.jpg" it does'nt show up.. But if I use 'http://' in front of it it shows the image...Always use an absolute path. That could be with the "http://", or you could do it more easily with just "/images/abc.jpg". 2)Try adding a DirectoryIndex index.php Quote Link to comment https://forums.phpfreaks.com/topic/290561-htaccess-problem/#findComment-1488460 Share on other sites More sharing options...
subhomoy Posted August 21, 2014 Author Share Posted August 21, 2014 Thanks for the help..... Quote Link to comment https://forums.phpfreaks.com/topic/290561-htaccess-problem/#findComment-1488480 Share on other sites More sharing options...
subhomoy Posted August 22, 2014 Author Share Posted August 22, 2014 @requinix still not working, showing the same error.... 404 not found 've change the file as u have said RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^([^/]+)/$ $1.php RewriteRule ^([^/]+)/([^/]+)/$ /$1/$2.php RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$ RewriteRule (.*)$ /$1/ [R=301,L] RewriteCond %{HTTP_HOST} !^www.example.com$ [NC] RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301] DirectoryIndex index.php Plz help me/...... Quote Link to comment https://forums.phpfreaks.com/topic/290561-htaccess-problem/#findComment-1488598 Share on other sites More sharing options...
requinix Posted August 22, 2014 Share Posted August 22, 2014 Put a [L,R] in each RewriteRule to see where you're being rewritten to; I think you'll end up at /new_folder.php. Quote Link to comment https://forums.phpfreaks.com/topic/290561-htaccess-problem/#findComment-1488624 Share on other sites More sharing options...
CroNiX Posted August 22, 2014 Share Posted August 22, 2014 (edited) That could cause several redirects since it will stop at the first L and redirect. Edited August 22, 2014 by CroNiX Quote Link to comment https://forums.phpfreaks.com/topic/290561-htaccess-problem/#findComment-1488634 Share on other sites More sharing options...
requinix Posted August 22, 2014 Share Posted August 22, 2014 I don't see how since none of the other RewriteRules will match it. # won't match because it doesn't end in a slash RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^([^/]+)/$ $1.php # doesn't contain slash, doesn't end in a slash RewriteRule ^([^/]+)/([^/]+)/$ /$1/$2.php # has a file extension RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$ RewriteRule (.*)$ /$1/ [R=301,L] # irrelevant to this discussion RewriteCond %{HTTP_HOST} !^www.example.com$ [NC] RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301] Quote Link to comment https://forums.phpfreaks.com/topic/290561-htaccess-problem/#findComment-1488651 Share on other sites More sharing options...
CroNiX Posted August 23, 2014 Share Posted August 23, 2014 Put a [L,R] in each RewriteRule I believe it would if you added L,R to EACH RewriteRule. Perhaps that's not what you meant since the htaccess you just posted doesn't do that. Quote Link to comment https://forums.phpfreaks.com/topic/290561-htaccess-problem/#findComment-1488654 Share on other sites More sharing options...
requinix Posted August 23, 2014 Share Posted August 23, 2014 Right. I put comments into the one you already had. I'm saying I don't see any opportunity for a loop. "/new_folder" will match the first set and redirect to "/new_folder.php". That then won't match any of the four sets and so... no loop. Could you just try it and see what happens? Quote Link to comment https://forums.phpfreaks.com/topic/290561-htaccess-problem/#findComment-1488655 Share on other sites More sharing options...
subhomoy Posted August 23, 2014 Author Share Posted August 23, 2014 If I add [L,R] in each RewriteRule then it redirects me to the another url Example I want to visits www.example.com/new_folder it took me to this url http://www.example.com/home3/superior/public_html/new_folder.php Is there anything that could solve the problem ???? plz help... Quote Link to comment https://forums.phpfreaks.com/topic/290561-htaccess-problem/#findComment-1488674 Share on other sites More sharing options...
requinix Posted August 23, 2014 Share Posted August 23, 2014 Huh. It did exactly what I said it would. The .php is being added because of the first rewriting rules RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^([^/]+)/$ $1.phpbecause "/new_folder" isn't a file. It should be ignoring directories, which you can do with RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^([^/]+)/$ $1.php 1 Quote Link to comment https://forums.phpfreaks.com/topic/290561-htaccess-problem/#findComment-1488755 Share on other sites More sharing options...
Richard_Grant Posted September 8, 2014 Share Posted September 8, 2014 (edited) I don't have time to actually help you but here is a .htaccess file i am currently using: DirectoryIndex board/index.php ############################################################################################ RewriteEngine on ########################## Redirect name/firstname/lastname ################################ RewriteCond %{REQUEST_URI} user/(.*)/(.*)/ RewriteRule user/(.*)/(.*)/ %{DOCUMET_ROOT}/board/test.php?firstname=$1&lastname=$2 RewriteCond %{REQUEST_URI} /user/(.*)/ RewriteRule user/(.*)/ %{DOCUMET_ROOT}/board/test.php?firstname=$1 RewriteCond %{REQUEST_URI} /user RewriteRule user/ %{DOCUMET_ROOT}/board/test.php RewriteCond %{REQUEST_URI} !(/$|\.) RewriteRule (.*) %{REQUEST_URI}/ ############################################################################################# RewriteCond %{REQUEST_URI} BETA/ [NC] RewriteRule BETA/ %{DOCUMET_ROOT} [NC] RewriteCond %{REQUEST_URI} construction/ [NC] RewriteRule construction/ %{DOCUMET_ROOT}/board/ECT/SITE_STATUS_/construction.php [NC] RewriteCond %{REQUEST_URI} ACCESS_DENIED/ [NC] RewriteRule ACCESS_DENIED/ %{DOCUMET_ROOT}/board/ECT/SITE_STATUS_/ACCESS_DENIED.php [NC] My directory is like this: -htdocs -board -index.php -construction.php -ACCESS_DENIED.php -css -php -js -resources Hope this helped Also press the Thanks on requinix Edited September 8, 2014 by Richard_Grant Quote Link to comment https://forums.phpfreaks.com/topic/290561-htaccess-problem/#findComment-1490310 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.