Forum Moderators: phranque
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?
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]
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
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?
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
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]