hackalive Posted August 21, 2011 Share Posted August 21, 2011 So I thought at first my server might be incorrectly configured because no supplied rewrite would work but ... RewriteEngine on RewriteRule ^old.html$ new.html does, so what I need is a working rewrite that allows a user to type: http://www.mydomain.com/contact and that will display the page http://www.mydomain.com/contact.php with the url bar still showing http://www.mydomain.com/contact, like the above sample Quote Link to comment https://forums.phpfreaks.com/topic/245346-a-working-rewrite/ Share on other sites More sharing options...
hackalive Posted August 21, 2011 Author Share Posted August 21, 2011 So a development Thanks to cags RewriteEngine On RewriteCond %{REQUEST_URI} !-f RewriteCond %{REQUEST_URI} !-d RewriteRule ^([^/.]+)/?$ /$1.php [L] This will allow me to type http://www.mydomain.com/ent and see root/ent.php BUT if there is also an ent foler in root it makes it automatically go to http://www.mydomain.com/ent/ and then breaks all the CSS and also is annoying So I need to figure out why this does this Quote Link to comment https://forums.phpfreaks.com/topic/245346-a-working-rewrite/#findComment-1260117 Share on other sites More sharing options...
hackalive Posted August 21, 2011 Author Share Posted August 21, 2011 After taking time to re-read and investigation with trial and error the stuff from cags earlier I now have this RewriteEngine On RewriteCond %{REQUEST_URI} !-f RewriteCond %{REQUEST_URI} !-d RewriteRule ^([^/.]+)/?$ /$1.php [L] RewriteRule ^([^/.]+)/([^/.]+)/?$ /$1/$2.php [L] Only ONE thing really annoys me with this if I do http://www.mydomain.com/corporate/bios the URL stays looking that way in the browser YAY BUT if I do http://www.mydomain.com/corporate the URL automatically changes to http://www.mydomain.com/corporate/ .... I would rather it did not do that ... one last hurdle Quote Link to comment https://forums.phpfreaks.com/topic/245346-a-working-rewrite/#findComment-1260120 Share on other sites More sharing options...
hackalive Posted August 21, 2011 Author Share Posted August 21, 2011 This ... RewriteEngine On RewriteCond %{REQUEST_URI} !-f RewriteCond %{REQUEST_URI} !-d RewriteRule ^([^/.]+)?$ /$1.php [L] RewriteRule ^([^/.]+)/([^/.]+)/?$ /$1/$2.php [L] still sends it to corporate/ but now returns a FORBIDDEN error as well Quote Link to comment https://forums.phpfreaks.com/topic/245346-a-working-rewrite/#findComment-1260122 Share on other sites More sharing options...
Jumpy09 Posted August 21, 2011 Share Posted August 21, 2011 I just tested this and it works for me. I get sent to the folder/file.php when I do folder/file and sent to the file.php when I just do /file I have no idea why you would be getting a Forbidden Error. I tested using RewriteEngine On RewriteCond %{REQUEST_URI} !-f RewriteCond %{REQUEST_URI} !-d RewriteRule ^([^/.]+)?$ school/$1.php [L] RewriteRule ^([^/.]+)/([^/.]+)/?$ school/$1/$2.php [L] Edit: As for the RewriteRule ^([^/.]+)?$ school/$1.php [L] line I would put the trailing / back in it as it'll work either way. I don't have the / at the end for me, but the second one works with or without the trailing / whereas since I suggested you take it out of the first one, if you do www.domain.com/file/ it won't do anything. Quote Link to comment https://forums.phpfreaks.com/topic/245346-a-working-rewrite/#findComment-1260124 Share on other sites More sharing options...
hackalive Posted August 21, 2011 Author Share Posted August 21, 2011 I have this RewriteEngine On RewriteCond %{REQUEST_URI} !-f RewriteCond %{REQUEST_URI} !-d RewriteRule ^([^/.]+)?$ /$1.php [L] RewriteRule ^([^/.]+)/([^/.]+)/?$ /$1/$2.php [L] I go to http://www.mydomain.com/corporate it takes me straight to (the url looks like) http://www.mydomain.com/corporate/ still for http://www.mydomain.com/corporate/bios it works fine, its just any that are not within a folder htdocs/corporate.php Quote Link to comment https://forums.phpfreaks.com/topic/245346-a-working-rewrite/#findComment-1260125 Share on other sites More sharing options...
Jumpy09 Posted August 21, 2011 Share Posted August 21, 2011 As I said put the trailing slash back in the first rule RewriteEngine On RewriteCond %{REQUEST_URI} !-f RewriteCond %{REQUEST_URI} !-d RewriteRule ^([^/.]+)/?$ /$1.php [L] RewriteRule ^([^/.]+)/([^/.]+)/?$ /$1/$2.php [L] If you don't have it, it will try to access htdocs/corporate/ which I am guessing your settings are set to prevent directory access. As for why it is adding the trailing slash, I have no idea. Quote Link to comment https://forums.phpfreaks.com/topic/245346-a-working-rewrite/#findComment-1260127 Share on other sites More sharing options...
hackalive Posted August 21, 2011 Author Share Posted August 21, 2011 still takes me to corporate/ Quote Link to comment https://forums.phpfreaks.com/topic/245346-a-working-rewrite/#findComment-1260128 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.