Jump to content

A Working Rewrite


hackalive

Recommended Posts

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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 :)

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.