Go Back   CodingForums.com > :: Server side development > Apache configuration

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 03-07-2012, 11:10 AM   PM User | #1
coreteevee
New to the CF scene

 
Join Date: Mar 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
coreteevee is an unknown quantity at this point
htaccess within subdirectory help!

hi there! I'm new here so hello all, looking for a little help with my .htaccess file.
I'm not great with it but will try my best to explain.

I'm using htaccess to rewrite my urls:

http://www.domain.com/channel/1.php?id=$1 to
http://www.domain.com/channel/1.html

Now this used to work fine with the following in my htaccess:

RewriteEngine On
RewriteRule 1/(.*).html/ 1.php?id=$1
RewriteRule 1/(.*).html 1.php?id=$1

Sloppy I know and sorry for that but it worked.

Anyway the problem I have now is that I've had a shift around with domain changes etc and now as a result the subdirectory along with the .htaccess file is buried a folder further back

Since then I can't get the above rewrites to work and I think the reason is because of the change with folders within my server.
Any advice or help would be much appreciated.
If it makes a difference I use godaddy shared hosting
coreteevee is offline   Reply With Quote
Old 03-07-2012, 01:54 PM   PM User | #2
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,650
Thanks: 4
Thanked 2,451 Times in 2,420 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
If you've changed structure, you may need to change the rewrite rules. The pattern itself can remain unchanged, but the sub-directories may need to change.
By default rewrite will search your pattern above to find a subdirectory from this .htaccess' directory called 1/.*html, and map it back to a file called 1.php within this directory. If you need to move to the parent, start using / in your replacement where / represents your directory root.
So if you want to match site.com/sub/1/id.html to site.com/1.php?id=id, then you would need to use:
Code:
RewriteRule 1/(.*)\.html/? /1.php?id=$1
And place this .htaccess in /sub. If you want to fetch a .php buried within a sub-directory, you must target it as being in a sub-directory. You can also use rewrite conditions to determine where you are first, and match only based on those rules.
So yes the structure of the filesystem is very important in both your matching and your mapping rules. Changes to it will require rewriting the rewrite rule to properly match and replace.

This also hasn't a thing to do with PHP, moving to Apache Configurations forum.
Fou-Lu is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:00 PM.


Advertisement
Log in to turn off these ads.