Mutley Posted October 25, 2009 Share Posted October 25, 2009 At the moment I have the following .htaccess setup: mysite.com/contact it goes to mysite.com/contact.php Which is simple, but how would I do it so it also works with a trailing slash, e.g.: mysite.com/contact/ and mysite.com/contact goes to mysite.com/contact.php Then how would I make it so folders like /images/ or /js/ or /inc/ etc aren't confused as .php files? Thanks in advance. Quote Link to comment https://forums.phpfreaks.com/topic/178929-clean-but-clever-urls/ Share on other sites More sharing options...
cags Posted October 25, 2009 Share Posted October 25, 2009 You listed what your .htaccess file does, but not what it looks like... to work with the trailing slash you would try something along the lines of ^mysite.com/([^/])/?$ /mysite/$1.php With regards to not forwarding when the file actually exists you would use a RewriteRule such as... RewriteCond %{SCRIPT_FILENAME} !-d RewriteCond %{SCRIPT_FILENAME} !-f Quote Link to comment https://forums.phpfreaks.com/topic/178929-clean-but-clever-urls/#findComment-944078 Share on other sites More sharing options...
Mutley Posted October 25, 2009 Author Share Posted October 25, 2009 My .htaccess is this at the moment: RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.+)$ /$1.php [L,QSA] But it doesn't work if there's a trailing slash, it just brings up a Internal Server Error 500. I don't quite understand your line? Quote Link to comment https://forums.phpfreaks.com/topic/178929-clean-but-clever-urls/#findComment-944084 Share on other sites More sharing options...
cags Posted October 25, 2009 Share Posted October 25, 2009 RewriteRule ^(.+)/?$ /$1.php Quote Link to comment https://forums.phpfreaks.com/topic/178929-clean-but-clever-urls/#findComment-944085 Share on other sites More sharing options...
Mutley Posted October 25, 2009 Author Share Posted October 25, 2009 Nope. mysite.com/contact.php Works, as it should. mysite.com/contact Works mysite.com/contact/ Forbidden 500 Thanks for helping so far! Quote Link to comment https://forums.phpfreaks.com/topic/178929-clean-but-clever-urls/#findComment-944089 Share on other sites More sharing options...
cags Posted October 25, 2009 Share Posted October 25, 2009 Try... RewriteRule ^([^/]+)/?$ /$1.php Quote Link to comment https://forums.phpfreaks.com/topic/178929-clean-but-clever-urls/#findComment-944091 Share on other sites More sharing options...
Mutley Posted October 25, 2009 Author Share Posted October 25, 2009 Wahey, that works! Only problem is with a trailing slash, /contact/ it gets confused with where the images/css files are - probably because it thinks its a folder. Anyway around this? Thanks alot! Quote Link to comment https://forums.phpfreaks.com/topic/178929-clean-but-clever-urls/#findComment-944170 Share on other sites More sharing options...
cags Posted October 25, 2009 Share Posted October 25, 2009 It sounds like you need to change your relative paths. But I'm not really sure, because I'm not certain what your talking about. Quote Link to comment https://forums.phpfreaks.com/topic/178929-clean-but-clever-urls/#findComment-944173 Share on other sites More sharing options...
mga_ka_php Posted November 7, 2009 Share Posted November 7, 2009 Wahey, that works! Only problem is with a trailing slash, /contact/ it gets confused with where the images/css files are - probably because it thinks its a folder. Anyway around this? Thanks alot! got the same problem which i'm looking for a solution. Quote Link to comment https://forums.phpfreaks.com/topic/178929-clean-but-clever-urls/#findComment-952924 Share on other sites More sharing options...
mga_ka_php Posted November 7, 2009 Share Posted November 7, 2009 the problem if there is a trailing slash, the images and css doesn't load. Quote Link to comment https://forums.phpfreaks.com/topic/178929-clean-but-clever-urls/#findComment-952930 Share on other sites More sharing options...
isedeasy Posted December 9, 2009 Share Posted December 9, 2009 try using absolute paths Quote Link to comment https://forums.phpfreaks.com/topic/178929-clean-but-clever-urls/#findComment-974274 Share on other sites More sharing options...
mga_ka_php Posted December 15, 2009 Share Posted December 15, 2009 fixed my problem by adding <base href="http://www.mydomain.com" /> to html Quote Link to comment https://forums.phpfreaks.com/topic/178929-clean-but-clever-urls/#findComment-977401 Share on other sites More sharing options...
Mutley Posted December 29, 2009 Author Share Posted December 29, 2009 fixed my problem by adding <base href="http://www.mydomain.com" /> to html Thanks regiemon! That's come in handy. I'm having issues with using this .htaccess in subdirectories however, it trys to use the root domain, rather than the subdirectory, for example: mysite.co.uk/test/site/about Trys to goto mysite.co.uk/about I did this: RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^mysite.co.uk/test/site/([^/]+)/?$ /$1.php Which goes to the correct URL but does a "Not found" error unless I include the *.php extension. Any ideas? Thanks alot and happy holidays! Quote Link to comment https://forums.phpfreaks.com/topic/178929-clean-but-clever-urls/#findComment-985432 Share on other sites More sharing options...
mga_ka_php Posted January 31, 2010 Share Posted January 31, 2010 any advice about Mutley problem. i wanna know it also. Quote Link to comment https://forums.phpfreaks.com/topic/178929-clean-but-clever-urls/#findComment-1004566 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.