mod_rewrite messing up directories

Discussion in 'Apache' started by Tipem, Jul 25, 2006.

  1. #1
    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
    Code (markup):
    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 :)
     
    Tipem, Jul 25, 2006 IP
  2. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #2
    Change

    RewriteRule ^(.*)/(.*)/ index.php?cat=$1&page=$2
    Code (markup):
    to for example

    RewriteRule ^blog/(.*)/(.*)/$ index.php?cat=$1&page=$2 [L]
    Code (markup):
     
    Nintendo, Jul 25, 2006 IP
  3. Tipem

    Tipem Active Member

    Messages:
    93
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    91
    #3
    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]
    Code (markup):
    That's my code now.
     
    Tipem, Jul 25, 2006 IP
  4. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #4
    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 /
     
    Nintendo, Jul 25, 2006 IP
  5. Tipem

    Tipem Active Member

    Messages:
    93
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    91
    #5
    Somebody said this to me:

    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]
    Code (markup):
    mysite.com/blogs/insertname/ is still not accessible.
     
    Tipem, Jul 26, 2006 IP
  6. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #6
    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.
     
    Nintendo, Jul 26, 2006 IP