Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
03-07-2012, 11:10 AM #1
- Join Date
- Mar 2012
- Thanked 0 Times in 0 Posts
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:
Now this used to work fine with the following in my htaccess:
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
03-07-2012, 01:54 PM #2
- Join Date
- Sep 2002
- Saskatoon, Saskatchewan
- Thanked 2,659 Times in 2,628 Posts
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:
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.Code:RewriteRule 1/(.*)\.html/? /1.php?id=$1
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.