Simple .htaccess

Need help installing PHP, configuring a script, or configuring a server? Then come on in and post your questions! We'll try to help the best we can!

Moderator: General Moderators

Post Reply
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Simple .htaccess

Post by alex.barylski »

Edit: This seems to work, however on directory requests I'm not getting index.php (or default script) - how I add that?

Code: Select all

RewriteEngine on
RewriteBase /

RewriteRule ^(.+)$ index.php?path=$1 [QSA]

Code: Select all

Options +FollowSymLinks
RewriteEngine on
RewriteBase /

#RewriteCond %{REQUEST_FILENAME} [NC]
RewriteRule ^(.+).php$ index.php?page=$1 [QSA]
I borrowed this from CMSMS thinking it should be a simple matter...unfortunately my understanding of regex is not where it could be. :P

All I need it to do is this:

1) When passed a file w/ path I need that path to be passed to index.php (inside docroot).
2) Keep or persist the GP{C} variables so I do not have to parse the URL manually inside script
3) If the requested file already exists, who cares, ignore it and send it's path to index.php instead

Can someone please give me the proper set of instructions to get this fired up?

Thanks :)
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

What's wrong with what you've got? You're not getting a page at all?
User avatar
Gente
Forum Contributor
Posts: 252
Joined: Wed Jun 13, 2007 9:43 am
Location: Ukraine, Kharkov
Contact:

Re: Simple .htaccess

Post by Gente »

Hockey wrote:

Code: Select all

....
RewriteRule ^(.+).php$ index.php?page=$1 [QSA]

Code: Select all

RewriteRule ^(.+)\.php$ index.php?page=$1 [QSA]
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Post by alex.barylski »

Update: It's just one directory within the hierarchy that needs public access, so cannot I not use a simple alias after that last rewrite rule???

Code: Select all

/index.php
 /assets/
 /core/
 /temp/
Core and Temp do not and should not be accessible directly from URL requests. Everything inside assets however I want accessed normally, because they are images, JS, etc which compose the index.php output...

--- Done Edit ---

Everything is fine, but now I need the .htaccess to ignore a directory named 'assets'

Code: Select all

RewriteEngine on
RewriteBase /

RewriteRule ^(.+)$ index.php?path=$1 [QSA]
I have tried adding the rule:

Code: Select all

RewriteRule !(assets)
But That choked the system...I'm not sure where or how I add exceptions to the above "redirect everything to index.php" rule :)
User avatar
Gente
Forum Contributor
Posts: 252
Joined: Wed Jun 13, 2007 9:43 am
Location: Ukraine, Kharkov
Contact:

Post by Gente »

Code: Select all

RewriteEngine on
RewriteBase /

RewriteRule ^assets/ - [L]
RewriteRule ^(.+)$ index.php?path=$1 [QSA]
Try it
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Post by alex.barylski »

Perfect, thanks :)

I had something alsmot like that, missing the '-' though which seems to be the critical factor.
Post Reply