Forum Moderators: phranque

Message Too Old, No Replies

Problem changing .htaccess

         

Karma

12:16 am on Dec 28, 2006 (gmt 0)

10+ Year Member



Hi all,

I have a domain for my website design business that is used as the main/default domain of my hosting account. In the root public_html folder, I have a single .htaccess file containing the following:

# -FrontPage-

IndexIgnore .htaccess */.?* *~ *# */HEADER* */README* */_vti*

<Limit GET POST>
order deny,allow
deny from all
allow from all
</Limit>
<Limit PUT DELETE>
order deny,allow
deny from all
</Limit>
AuthName www.mydomainname.co.uk
AuthUserFile /home/myaccountname/public_html/_vti_pvt/service.pwd
AuthGroupFile /home/myaccountname/public_html/_vti_pvt/service.grp

I've not got a clue what this does, so I deleted it.

Only joking ;)

I'm trying to produce clean urls for this domain, so I tried adding the following rules to either the start or the end.

RewriteEngine On
RewriteRule ^([^\.]+)/([^\.]+)/?$ /index.php?section=$1&page=$2 [QSA,L]
RewriteRule ^([^\.]+)/?$ /index.php?section=$1 [QSA,L]

Now, if I add the code, the rewrite works fine and I have clean URLs, but anything in the subfolders of the root public_html are screwed up (subdomains etc).

Hope that makes sense in someway to someone :/

Any ideas?

jdMorgan

12:29 am on Dec 28, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



> anything in the subfolders of the root public_html are screwed up (subdomains etc).

Screwed-up how?

You code does not 'define' any special subfolders, so perhaps you need to add exclusions for them. As written, your code will rewrite *any* URL-paths of the form /part1/part2/ or /part1/ with or without a trailing slash, to index.php, as long as neither part1 nor part2 contains a period.

In order to improve efficiency and demonstrate (roughly) what might be needed:


RewriteEngine on
RewriteCond %{REQUEST_URI} !^/common_images/
RewriteCond %{REQUEST_URI} !^/common_scripts/
RewriteRule ^([^/]+)/([^./]+)/?$ /index.php?section=$1&page=$2 [QSA,L]
RewriteRule ^([^./]+)/?$ /index.php?section=$1 [QSA,L]

That fixes a couple of problems with the patterns, and prevent the rule from being applied for common image and script subdirectories.

It often helps when thinking about rewriting to consider not only what you want to rewrite, but also what you don't want to rewrite. You must make this explicitly clear to mod_rewrite in the patterns and the logical structure of the code.

Jim

Karma

1:45 am on Dec 28, 2006 (gmt 0)

10+ Year Member



Hey jdMorgan,

Many thanks for your quick reply, it really was appreciated. I agree with your point of thinking about stuff that doesn't need to be included, in all honesty, it's the stuff that shouldn't be re-written that causes 75% of my problems.

I've made the change you suggested, but I still have the same problem:

www.mydomainname.co.uk works fine.

www.mydomainname.co.uk/_forums/ does not work. This url should take me to my phpbb forums, but is instead being treated as a page of the site at www.mydomain.co.uk.

I have added the following code:

RewriteCond %{REQUEST_URI}!^/_forums/

Any other ideas?

jdMorgan

1:58 am on Dec 28, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Well, there's always a case that gets by me...

You'll need appropriate exclusions for each rule, since RewriteConds only affect the single RewriteRule that follows them. Adding on to my previous example:
[code]
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/common_images/.
RewriteCond %{REQUEST_URI} !^/common_scripts/.
RewriteRule ^([^/]+)/([^./]+)/?$ /index.php?section=$1&page=$2 [QSA,L]
#
RewriteCond %{REQUEST_URI} !^/_forums/?
RewriteRule ^([^./]+)/?$ /index.php?section=$1 [QSA,L]
[code]
Jim

Karma

10:40 am on Dec 28, 2006 (gmt 0)

10+ Year Member



Still get the same problem :/

Karma

9:08 pm on Dec 28, 2006 (gmt 0)

10+ Year Member



Anyone have any other ideas? If not I'll just have to stick to the old url structure.

Karma

11:04 pm on Dec 28, 2006 (gmt 0)

10+ Year Member



All fixed! As you probably guessed - I was doing something stupid. I forgot that the example folder I gave you (_forums) was only an example, the actual folder I was trying to exclude was _forum, and I was pasting the code you wrote.

Ooops :(

Anyway, I still have some troubles with some other folders that had domains assigned to them, so I added 'rewriteengine off' at the subfolder roots and all is good.

Thanks again for the help Jim :)

[edited by: Karma at 11:05 pm (utc) on Dec. 28, 2006]

jdMorgan

12:25 am on Dec 29, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Glad you got it fixed!

Jim