Magazine Subscriptions - Jordans - Free Advertising - Home Loans - Buy Anything On eBay

PDA

View Full Version : mod_rewrite messing up directories


Tipem
Jul 25th 2006, 2:52 pm
Hello,

I have a mod_rewrite rule in my .htaccess file. It makes index.php?cat=this&page=that into mysite.com/this/that/.

Now, I also have some blogs, which are located at mysite.com/blogs/INSERTNAMEHERE/. Because this is the same pattern as my mod_rewrite, it picks up the index.php, but /blogs/INSERTNAMEHERE/ is a real directory. Is there any page I can make Apache ignore /blogs/insertnamehere/ and display the actual contents in the directory (and NOT use mod_rewrite)?

Here are my rewrite rules if this helps any:

Options +FollowSymlinks
RewriteEngine On
RewriteCond %{REQUEST_URI}\\/%{HTTP_HOST}/www.//s%{HTTPS} ^/+(.+/)?[^.]*[^/]\\(/)([^w][^w][^w][^.].*/(www\.)|.*)//((s)on|s.*)$ [OR,NC]
RewriteCond %{HTTP_HOST}/www.//s%{HTTPS} ^(/)?(/)?([^w][^w][^w][^.].*/(www\.))//((s)on|s.*)$ [NC]
RewriteRule ^ http%6://%4%{HTTP_HOST}%{REQUEST_URI}%2 [L,R=301]
RewriteRule ^(.*)/(.*)/ index.php?cat=$1&page=$2

I just discovered that I can't load images either because it's in the form of mysite.com/images/this/that.gif or whatever. UGH! There must be a simple fix, I'm just not very good with mod_rewrite :mad: Oh and, yes I do know that I'm misusing the atom (:

Thanks in advanced :)

Nintendo
Jul 25th 2006, 4:03 pm
Change

RewriteRule ^(.*)/(.*)/ index.php?cat=$1&page=$2

to for example

RewriteRule ^blog/(.*)/(.*)/$ index.php?cat=$1&page=$2 [L]

Tipem
Jul 25th 2006, 5:08 pm
Thanks very much. This has fixed my images problem. I now can pull up images and such. :)

However, I still cannot access my blogs at mysite.com/blogs/INSERTNAMEHERE/. Mod_rewrite is still treating it as a category and page name.

Options +FollowSymlinks
RewriteEngine On
RewriteCond %{REQUEST_URI}\\/%{HTTP_HOST}/www.//s%{HTTPS} ^/+(.+/)?[^.]*[^/]\\(/)([^w][^w][^w][^.].*/(www\.)|.*)//((s)on|s.*)$ [OR,NC]
RewriteCond %{HTTP_HOST}/www.//s%{HTTPS} ^(/)?(/)?([^w][^w][^w][^.].*/(www\.))//((s)on|s.*)$ [NC]
RewriteRule ^ http%6://%4%{HTTP_HOST}%{REQUEST_URI}%2 [L,R=301]
RewriteRule ^(.*)/(.*)/$ index.php?cat=$1&page=$2 [L]

That's my code now.

Nintendo
Jul 25th 2006, 6:37 pm
Is

RewriteRule ^(.*)/(.*)/$ index.php?cat=$1&page=$2 [L]

still in the code? That would mess it up. You have to have something unique in the fake URLs to keep from messing with real directories/directories. Just changing it to directory/file.html would fix it, if you don't want a third 'directory' and don't have real .html files there.

What are the RewriteCond lines and first RewriteRule line for? And change

RewriteEngine on

to

RewriteEngine on
RewriteBase /

Tipem
Jul 26th 2006, 12:37 pm
Somebody said this to me:

Now, assuming that we're past the "learn some regex" problem, the use of RewriteCond could help. Specifically,

RewriteCond %{REQUEST_URI} !-f
RewriteCond %{REQUEST_URI} !-d
RewriteRule ^/{regex} {redirect}

will ensure that you do NOT redirect if the URI is either a file or directory. Once again, though, that's in my signature article ("lessons learned" from 1 1/2 years helping others in this forum).

However, I dont really know what he's talking about. I dont mean to be a complete n00b, although I am to this, I would appreciate your comments. My code is as follows:

Options +FollowSymlinks
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_URI}\\/%{HTTP_HOST}/www.//s%{HTTPS} ^/+(.+/)?[^.]*[^/]\\(/)([^w][^w][^w][^.].*/(www\.)|.*)//((s)on|s.*)$ [OR,NC]
RewriteCond %{HTTP_HOST}/www.//s%{HTTPS} ^(/)?(/)?([^w][^w][^w][^.].*/(www\.))//((s)on|s.*)$ [NC]
RewriteRule ^ http%6://%4%{HTTP_HOST}%{REQUEST_URI}%2 [L,R=301]

RewriteCond %{REQUEST_URI} !-f
RewriteCond %{REQUEST_URI} !-d
RewriteRule ^(.*)/(.*)/$ index.php?cat=$1&page=$2 [L]

mysite.com/blogs/insertname/ is still not accessible.

Nintendo
Jul 26th 2006, 1:16 pm
If you're only trying to change the URLs...

Options +Indexes
Options +FollowSymlinks
RewriteEngine on
RewriteBase /
RewriteRule ^([^.]+)/([^.]+)$ index.php?cat=$1&page=$2 [L]

Except your real blog .com/directoirs/directories/ will be messed up as long as you don't have the last line be something like

RewriteRule ^(.*)/(.*)\.html$ index.php?cat=$1&page=$2 [L]

to make the URLs different from real URLs, as for example domain.com/directory/file.html.