views:

44

answers:

2

i have a domain with a website in a folder.

i.e http://domain.com.au/website/page.php

i only have access to .htaccess files to make the rules. i would like my url to look like this..

http://domain.com.au/page

so in essence i want to drop the subfolder its sitting in, and the php extention.

All links in my php are structured like this though

<a href="/website/page.php">page link</a>

this is the same for js and css. they are all referenced from the 'website' folder.

will the rewrite mean i have to change all my links?

priority is dropping the folder from the url, not so much the php extension.

A: 

1) You could move all the files to the root web directory and run the website from there. 2) You would have to manually modify every link to remove the website directory from the beginning and then use the .htaccess file to redirect the pages back to the appropriate page. If you're going to do it this way, you might as well remove the PHP extension...

RewriteEngine On
Options +FollowSymLinks

RewriteCond %{HTTP_HOST} ^domain.com.au$ [NC]
RewriteRule ^(.*)/ website/$1.php [L]

You may have to modify the website/$1.php part to include your entire root directory in some cases, but that should work as long as the .htaccess file is in the root web directory. That will redirect any page in the form 'http://domain.com.au/page' to 'http://domain.com.au/website/page.php' while keeping the URL the same in the address bar.

animuson
Why exactly are you checking the HTTP_HOST? `RewriteCond %{HTTP_HOST} ^domain.com.au$ [NC]`
Dan Beam
Also why are both you, and Raz using the last flag. It's completely pointless when you have one rewrite rule.
anomareh
i forgot to mention there are subfolders in /websiteso this rule doesnt work. so it needs to work with domain.com.au/website/page.php AND domain.com.au/website/bla/page2.phpetcalso not working for js and css
lukemh
A: 
<IfModule mod_rewrite.c>
    RewriteEngine on

        RewriteRule    ^page\_one/(.*)/([0-9]{1,6})/?$ webroot/products/products/view/$2    [L]

 </IfModule>

this htaccess code redirects all trafic from www.domain.com/page_one/anything/numeral

to the page www.domain.com/webroot/products/products/view/same numeral

for your example, something like

    RewriteRule    ^page?$ website/page.php$2    [L]

note, this works for "page" as a string, if you need other functions , change it

for more insight, you might want to take a look at this link : http://www.javascriptkit.com/howto/htaccess.shtml

Raz