htaccess in root and subdir with rewrite

Discuss practical ways rearrange URLs using mod_rewrite.

htaccess in root and subdir with rewrite

Postby gertje8 » Thu Oct 08, 2009 10:31 am

Hello,

It's been a while since a visited this site... so that means I'm having a problem.

I have one site wich is getting content from another server and displaying the menubar as a foldername. This done with a php script wich you can find a part of it...

Code: Select all
f($_GET["pagetype"]==""){
    $data = file_get_contents("http://www.blabla.nl/site/build/?blabla_id=".$blabla_id."&info=".$blabla_info."&build_id=".$blabla_id);
}


My htacces in the root is like this. This is a subdomain. That's why the folder is displayed in the htaccess.
and I might think that the menubar everytime is redirecting to the main folder instead of the folder asked by the php script.

In short terms.

http://www.blabla.nl/content/

is not working and displays http://www.blabla.nl

Code: Select all
Options +FollowSymlinks

RewriteEngine On
RewriteRule ^/*(.+/)?([^.]*[^/])$ http://%{HTTP_HOST}/$1$2/ [L,R=301]

#Rule-0
RewriteCond   %{HTTP_HOST}   ^domain.com$   
RewriteCond   %{REQUEST_URI}   !^/domain/   
RewriteRule   (.*)   /domain/$1   

#Rule-1
RewriteCond   %{HTTP_HOST}   ^www.domain.com$   
RewriteCond   %{REQUEST_URI}   !^/domain/   
RewriteRule   (.*)   /domain/$1   


The htacces in my subdir rewrites the url and can be found here.

Code: Select all
RewriteEngine on
RewriteBase /


RewriteRule ^content/.*/([0-9]+)\/([0-9]+)\/$ index.php?pagetype=3&category_id=$1&page=$2
RewriteRule ^content/.*/([0-9]+)\/([0-9]+)\/$ index.php?pagetype=2&category_id=$1&page=$2

RewriteRule ^content/([0-9]+)\/$ index.php?pagetype=2&page=$1
RewriteRule ^content/([0-9]+)\/$ index.php?pagetype=3&page=$1


RewriteRule ^content$ index.php?pagetype=2
RewriteRule ^content$ index.php?pagetype=3


RewriteRule ^content/([0-9]+)\/.*/$ index.php?pagetype=8&post_id=$1
RewriteRule ^other_content/([0-9]+)\/.*/$ index.php?pagetype=9&content_id=$1

ErrorDocument 401 /index.php
ErrorDocument 403 /index.php
ErrorDocument 404 /index.php
ErrorDocument 405 /index.php
ErrorDocument 407 /index.php
ErrorDocument 500 /index.php


Any suggestions?

Kindly regards,

Gert
gertje8
 
Posts: 9
Joined: Tue May 19, 2009 5:54 am

Postby richardk » Thu Oct 08, 2009 10:54 am

I have one site wich is getting content from another server and displaying the menubar as a foldername. This done with a php script wich you can find a part of it...

What happens if you make a request in your browser instead of the script?

Try replacing the first mod_rewrite with
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{DOCUMENT_ROOT}/example%{REQUEST_URI}/ -d
RewriteRule [^/]$ %{REQUEST_URI}/ [R=301,L]

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$ [NC]
RewriteRule ^(.*)$ /example/$1 [QSA,L]


And the second with
Code: Select all
ErrorDocument 401 /index.php
ErrorDocument 403 /index.php
ErrorDocument 404 /index.php
ErrorDocument 405 /index.php
ErrorDocument 407 /index.php
ErrorDocument 500 /index.php

Options +FollowSymLinks

RewriteEngine On

RewriteRule ^content/.+/([0-9]+)/([0-9]+)/$       index.php?pagetype=3&category_id=$1&page=$2 [QSA,L]
RewriteRule ^other_content/.+/([0-9]+)/([0-9]+)/$ index.php?pagetype=2&category_id=$1&page=$2 [QSA,L]

RewriteRule ^content/([0-9]+)/$       index.php?pagetype=2&page=$1 [QSA,L]
RewriteRule ^other_content/([0-9]+)/$ index.php?pagetype=3&page=$1 [QSA,L]


RewriteRule ^content$       index.php?pagetype=2 [QSA,L]
RewriteRule ^other_content$ index.php?pagetype=3 [QSA,L]


RewriteRule ^content/([0-9]+)/.+/$       index.php?pagetype=8&post_id=$1    [QSA,L]
RewriteRule ^other_content/([0-9]+)/.+/$ index.php?pagetype=9&content_id=$1 [QSA,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby gertje8 » Thu Oct 08, 2009 11:09 am

richardk wrote:
I have one site wich is getting content from another server and displaying the menubar as a foldername. This done with a php script wich you can find a part of it...

What happens if you make a request in your browser instead of the script?

Try replacing the first mod_rewrite with
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{DOCUMENT_ROOT}/example%{REQUEST_URI}/ -d
RewriteRule [^/]$ %{REQUEST_URI}/ [R=301,L]

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$ [NC]
RewriteRule ^(.*)$ /example/$1 [QSA,L]


And the second with
Code: Select all
ErrorDocument 401 /index.php
ErrorDocument 403 /index.php
ErrorDocument 404 /index.php
ErrorDocument 405 /index.php
ErrorDocument 407 /index.php
ErrorDocument 500 /index.php

Options +FollowSymLinks

RewriteEngine On

RewriteRule ^content/.+/([0-9]+)/([0-9]+)/$       index.php?pagetype=3&category_id=$1&page=$2 [QSA,L]
RewriteRule ^other_content/.+/([0-9]+)/([0-9]+)/$ index.php?pagetype=2&category_id=$1&page=$2 [QSA,L]

RewriteRule ^content/([0-9]+)/$       index.php?pagetype=2&page=$1 [QSA,L]
RewriteRule ^other_content/([0-9]+)/$ index.php?pagetype=3&page=$1 [QSA,L]


RewriteRule ^content$       index.php?pagetype=2 [QSA,L]
RewriteRule ^other_content$ index.php?pagetype=3 [QSA,L]


RewriteRule ^content/([0-9]+)/.+/$       index.php?pagetype=8&post_id=$1    [QSA,L]
RewriteRule ^other_content/([0-9]+)/.+/$ index.php?pagetype=9&content_id=$1 [QSA,L]


When I make a request in the browser to the subdir it is displaying the main page of the domain wich is in the folder.

When i pass the variables after the url then it's working perfect.
like this it is working correct.

http://www.blabla.nl/index.php?pagetype ... $1&page=$2

The htaccess in the subfolder is not making any problems. I'm for sure. I also deleted the htaccess file which is rewriting those nasty urls.

When I place your htacces example the main site is working.

Code: Select all
RewriteCond %{DOCUMENT_ROOT}/example%{REQUEST_URI}/ -d
RewriteRule [^/]$ %{REQUEST_URI}/ [R=301,L]

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$ [NC]
RewriteRule ^(.*)$ /example/$1 [QSA,L]


The menubar wich is pointing to http://www.blabla.nl/content/ is displaying thepage cannot be found!
So I might think that the problem is really in the root or with the php script and the variables.
gertje8
 
Posts: 9
Joined: Tue May 19, 2009 5:54 am

Postby richardk » Thu Oct 08, 2009 12:16 pm

So I might think that the problem is really in the root or with the php script and the variables.

echo the file_get_contents() URL out to check it's correct. If you still think it's a mod_rewrite problem post back here.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby gertje8 » Thu Oct 08, 2009 12:30 pm

richardk wrote:
So I might think that the problem is really in the root or with the php script and the variables.

echo the file_get_contents() URL out to check it's correct. If you still think it's a mod_rewrite problem post back here.


Thnx for support. Going to check the code first and test it in a root domain to see if it is working.
gertje8
 
Posts: 9
Joined: Tue May 19, 2009 5:54 am


Return to Friendly URLs with Mod_Rewrite

Who is online

Users browsing this forum: No registered users and 6 guests

cron