Forum Moderators: phranque
I am new to Apache mod rewrite and in learning phase, I would like a little help to understand it better.
My problem is frameset page not working with url rewrite!
I am using wildcard DNS to handle my subdomains its been redirected to catchfolder from Cpanel. Again I have virtual folders. I am catching virtual subdomain and virtual folder for redirect. My target page is frameset page which I can't change to normal page, as its my requirement.
I had a following codes which works fine but not working with the frameset page without URL change, it works on frameset page with URL change.
eg: [wildcard-sd.domain.com...]
redirect to [domain.com...]
my .htaccess file is in catchfolder
Codes:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.domain\.com [NC]
RewriteCond %{HTTP_HOST} ([^\.]+)\.domain\.com [NC]
RewriteRule (.*) [domain.com...] [QSA,L]
This works fine with frameset page but the URL also gets changed from
[wildcard-sd.domain.com...]
TO
[domain.com...]
Which I dont want. Now if I change the RewriteRule to this
RewriteRule (.*) index.php?sd=%1&fd=$1 [QSA,L]
It works and even the URL doesnt changes but the frameset page is not working, if I put a normal page without frameset it works fine.
I want redirect + URL should not change + frameset target page.
Any help will be appreciated.
Thanks and Regards,
Gonzo
RewriteCond $1 !^index\.php$
RewriteCond %{HTTP_HOST} !^www\.example\.com [NC]
RewriteCond %{HTTP_HOST} ([^\.]+)\.example\.com
RewriteRule ^(.*)$ /catchfolder/index.php?sd=%1&fd=$1 [QSA,L]
Thanks for your reply.
I had tired your codes but getting Internal Server Error with full index.php filepath.
eg:
RewriteRule ^(.*)$ /catchfolder/index.php?sd=%1&fd=$1 [QSA,L]
If I change the RewriteRule to just index.php as it is in catchfolder itself where my .htaccesss file is, it works but my page with frameset is not getting displayed only blank page.
eg:
RewriteRule ^(.*)$ index.php?sd=%1&fd=$1 [QSA,L]
As you advice to explicity stop the rule from recursively rewriting index.php to itself, still its looping I guess.
Thanks and Regards,
Gonzo
Look at your server error log file, and check the client requests and server responses using the "Live HTTP Headers" add-on for Firefox and Mozilla browsers.
It's also possible that the cPanel set-up is incorrect or just "weird" and that it is interfering with the expected operation of the code; Looking at the "failed" filepaths shown in the error log file will likely help identify this potential problem.
Jim
Be very sure about where you put the .htaccess file with this code, and make sure that the correct server-root-relative index.php filepath is specified in the RewriteRule's substitution path.
==> My .htaccess file is in subfolder named catchfolder. I had created a subdomain from cPanel i.e *.domain.com which redirects to catchfolder. Using server root relative path it works but again not with frameset page.
Server root relative path Document Root: /home/account/public_html/domain/catchfolder/index.php
Look at your server error log file, and check the client requests and server responses using the "Live HTTP Headers" add-on for Firefox and Mozilla browsers.
==>My server error logs doesnt consist of target page errors and I am not able to access apache error logs. About "Live HTTP Headers" firefox addon again only shows:
HTTP/1.x 500 Internal Server Error
Date: Fri, 27 Mar 2009 18:56:35 GMT
Server: Apache/2.2.11 (Unix) mod_ssl/2.2.11 OpenSSL/0.9.8i DAV/2 mod_auth_passthrough/2.1 mod_bwlimited/1.4 FrontPage/5.0.2.2635
Content-Length: 860
Connection: close
Content-Type: text/html; charset=iso-8859-1
If I just use /catchfolder/index.php.
It's also possible that the cPanel set-up is incorrect or just "weird" and that it is interfering with the expected operation of the code; Looking at the "failed" filepaths shown in the error log file will likely help identify this potential problem.
==> My server error logs doesnt shows any failed filepaths with the said target link. cPanel setup I am not sure what could be wrong.
Regards,
Gonzo
RewriteEngine on
RewriteCond $1 !=index.php
RewriteCond %{HTTP_HOST} !^www\.example\.com [NC]
RewriteCond %{HTTP_HOST} ^([^.]+)\.example\.com
RewriteRule ^(.*)$ /index.php?sd=%1&fd=$1 [QSA,L]
Thanks for the reply.
With your solution I am getting this error:
Redirect Loop
Firefox has detected that the server is redirecting the request for this address in a way that will never complete.
Live HTTP Headers:
HTTP/1.x 302 Moved Temporarily
Date: Sat, 28 Mar 2009 12:11:22 GMT
Server: Apache/2.2.11 (Unix) mod_ssl/2.2.11 OpenSSL/0.9.8i DAV/2 mod_auth_passthrough/2.1 mod_bwlimited/1.4 FrontPage/5.0.2.2635
X-Powered-By: PHP/5.2.8
Location: ../index.php
Content-Length: 0
Keep-Alive: timeout=5, max=80
Connection: Keep-Alive
Content-Type: text/html
@Jim
If I subsitute my RewriteRule:
From
RewriteRule ^(.*)$ index.php?sd=%1&fd=$1 [QSA,L]
With
RewriteRule ^([a-zA-Z0-9]+)/?$ index.php?sd=%1&fd=$1 [QSA,L]
It is wroking fine with frameset as my landing page, but one problem is coming i.e if my URL doesnt consist of any folder or file name in it, it is getting stuck into loop.
Working URL:
[wildcard-sd.domain.com...]
Not Working URL:
[wildcard-sd.domain.com...]
Thank you guys for helping me out, I would like you guys to comment each line so that I can learn what it is meant for, I want a solution but I want to learn as well.
My working solutions;
Options +FollowSymlinks
RewriteEngine On
RewriteCond $1 !^index\.php$
RewriteCond %{HTTP_HOST} !^www\.domain\.com [NC]
RewriteCond %{HTTP_HOST} ([^\.]+)\.domain\.com
RewriteRule ^([a-zA-Z0-9]+)/?$ index.php?sd=%1&fd=$1 [QSA,L]
Regards,
Gonzo
# Set required FollowSymlinks option to enable use of mod_rewrite
Options +FollowSymlinks
# Enable the rewriting engine
RewriteEngine On
#
# If requested URL-path has not already been rewritten to index.php
RewriteCond $1 !^index\.php$
# AND if requested hostname does NOT start with "www.example.com" (case-insensitive)
RewriteCond %{HTTP_HOST} !^www\.example\.com [NC]
# AND if first-level subdomain present, then extract it from the HTTP "Host" request header
RewriteCond %{HTTP_HOST} ([^\.]+)\.example\.com
# Then rewrite request to index.php with requested subdomain & URL-path as query string parameters
RewriteRule ^([b][0-9a-z]+[/b])/?$ index.php?sd=%1&fd=$1 [[b]NC,[/b]QSA,L]
Jim
You were right there was a conditional redirect into my script to home page, I was only focusing on the mod rewrite stuff why it is not working and overlooked the script redirect, which was getting fail due to condition not meeting.
Thanks a lot problem seems to be solved :)
@Jim
Thank you so much for your explanation with the commented codes. Everything seems to be working fine now. I am happy that I had learned something new :)
Thanks and Regards,
Gonzo