• About Sarwar
  • Portfolio
  • আমার বাংলা

sarwar's weblogs

~ story of web applications…..

sarwar's weblogs

Tag Archives: .htaccess

.htaccess killing 3 hours

17 Tuesday May 2011

Posted by Sarwar in .htaccess, Apache, CakePHP

≈ Leave a comment

Tags

.htaccess, apache, CakePHP, url rewrite


I’m working in cakephp for last two years, I developed and hosted many times, during hosting I got many problem all these are .htaccess related.

Today I tried to host one of my project, I created a server on rackspace cloud and installing all features apache, mysql, phpmyadmin and configure everything, I installed sugarcrm there and it worked, but when I tried to run my cakephp project, its always displaying “PAGE NOT FOUND”. the rewrite mdoule was on and i checked it working for others,

I checked apache error/access log, not clue found, doing some google no result, but I never give-up again trying to do some google got a reference in drupal site and check my apache configuration.

Only one thing I left in apache configuration.

// Open the apache site available
sudo nano /etc/apache2/sites-available/default

The article says that for URL rewriting we need to make “AllowOverride none” to “AllowOverride All”

I open that file and changed it.

<VirtualHost *:80>
        ServerAdmin webmaster@localhost

        DocumentRoot /var/www
        <Directory />
                Options FollowSymLinks
                AllowOverride All 
        </Directory>
        <Directory /var/www/>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride All 
                Order allow,deny
                allow from all
        </Directory>
...... 
......
...

Done, went to my site and its working properly, 🙂

Advertisement

Share this:

  • Tweet
  • Email

Like this:

Like Loading...

direct to specific page instead of get variable www.domain.com/username using php and .htaccess

31 Sunday Oct 2010

Posted by Sarwar in .htaccess, PHP

≈ 5 Comments

Tags

.htaccess, PHP, url rewrite


Sometime we need to get direct access any specific page. We need a user profile page http://www.domain.com/username, but our actual url is http://www.domain.com/profile/profile.php?username=Abc

I’m trying to describe how to make the url friendly, I used .htaccess and php for rewrite the url.
.htaccess

    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ index.php?uri=$1 [QSA,L]

In this case the uri took parameter after index.php file.
So if url is http://www.domain.com/username
uri will have the value uri=useranme

We need following code to retrieve the parameter.

 $_SERVER['QUERY_STRING']

I followed the following way inside index.php file to get the username

  $flag = false; 
  if(isset($_SERVER['QUERY_STRING']))
  {
      $q = $_SERVER['QUERY_STRING'];
      $data = explode("=",$q);  // Assume uri=username 
      if(isset($data[0]) && isset($data[1]) && $data[0] == 'uri')
      {
          $a = $data[1];
          $q = "SELECT * FROM user_profiles WHERE user_profile_name = '$a'";
          $cnt = mysql_num_rows(mysql_query($q));
          if($cnt > 0)
          {
             include("profile/profile.php");
             $flag = true;
          }
          
      }
      
  }
if($flag == false)
{
   include("home.php") // your index or homepage 
}

So above code I tried to find the uri and check it on database if username/profile name exists or not. If it found I include the profile page. if not then include the homepage. After including profile.php page, all variables (only above include) are available in profile.php file.

its working with me very well.

You may have better solutions. But I need it very urgent that’s why I write the code in this way. If you have better solution please share your thoughts.

Share this:

  • Tweet
  • Email

Like this:

Like Loading...

how to cakephp in a sub-directory, access it from root using .htaccess

16 Tuesday Mar 2010

Posted by Sarwar in CakePHP, PHP

≈ 13 Comments

Tags

.htaccess, CakePHP, sub-directory, url


Sometime we may need to put cakephp in a sub directory insted of document root directory, and we need to get the site from root.
Our document root directory is /httpdocs/ and we put the cakephp inside it /httpdocs /cake_sub/ and we want access the site from http://www.my-domain-name.com not http://www.my-domain-name.com/cake_sub

1. In this case we need to create a .htaccess file and put it to /httpdocs/ and the content is as follow

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteRule    ^$ cake_sub/app/webroot/    [L]
RewriteRule    (.*) cake_sub/app/webroot/$1 [L]
</IfModule>

So we need to on the RewriteEngine Now we need to edit the .htaccess files from the following locaiton

  • cake_sub/
  • cake_sub/app
  • cake_sub/webroot

2. Need to edit the .htaccess from /httpdocs/cake_sub as following


<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /cake_sub/
RewriteRule    ^$ app/webroot/    [L]
RewriteRule    (.*) app/webroot/$1 [L]
</IfModule>
3. Need to edit the .htaccess from /httpdocs/cake_sub/app as following
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /cake_sub/app/
RewriteRule    ^$    webroot/    [L]
RewriteRule    (.*) webroot/$1    [L]
</IfModule>

4. Need to edit the .htaccess from /httpdocs/cake_sub/app/webroot as following

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /cake_sub/app/webroot/
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
</IfModule>


Done, It worked with me and hope it’ll work with you too. I just put the document root httpdocs and sub directory name as an example.

Share this:

  • Tweet
  • Email

Like this:

Like Loading...

Author

  • Sarwar

Categories

  • .htaccess
  • Apache
  • API
  • CSS
  • Debug
  • Framework
    • CakePHP
  • HTML
  • JavaScript
    • Ajax
    • ckeditor
    • jquery
    • jQuery UI
    • tinymce
  • Joomla
    • Virtumart
  • Linux
  • MySQL
  • PHP
  • SVN
  • Twitter
  • WHM/cPanel
View Sarwar Hossain's profile on LinkedIn
Follow bdsarwar on Twitter

Tweets

  • RT @ESPNUK: If Erling Haaland wanted to match Cristiano Ronaldo's 700 league goals, he'd have to score 40 goals a season until the year 203…    1 month ago
  • RT @Cristiano: Great team effort and a good victory. We stand together. Let’s go, United! 💪🏽 https://t.co/GnjAR3oM3s    3 months ago
  • RT @Cristiano: Hard work always pays off 🙏🏽💪🏽 https://t.co/kMqIpB2nfV    5 months ago
  • RT @realDonaldTrump: Just finished a very good conversation with President Xi of China. Discussed in great detail the CoronaVirus that is r…    2 years ago
  • “Running a small business without a plan is a lot like driving without directions.” — @GoldmanSachs via @appexchange    6 years ago
  • RT @TechCrunch: 5K people turn up to catch Pokémon in Chicago tcrn.ch/2aaLRys https://t.co/VVQSd7nmN4    6 years ago

Flickr Photos

From Helipad ViewAbove the CloudHillNear to SkySunset Moment#sunset #beach #ocean #coxsbazar#jamroll #food #deliciousfood #homemade  #homemadefood#seaside #ocean #oceanview #travelphotography #coxsbazar #bayofbengal #travel #longestbeach#beach #lifeguard #seaside #holiday #tour #longestbeach #travel #travelphotography #coxsbazar #bayofbengal#resort #mountains
More Photos

Archives

  • February 2012 (1)
  • January 2012 (2)
  • August 2011 (1)
  • July 2011 (1)
  • June 2011 (2)
  • May 2011 (2)
  • April 2011 (1)
  • March 2011 (3)
  • December 2010 (3)
  • November 2010 (1)
  • October 2010 (4)
  • September 2010 (1)
  • June 2010 (1)
  • May 2010 (2)
  • April 2010 (1)
  • March 2010 (1)
  • January 2010 (2)
  • July 2009 (1)
  • January 2009 (1)
  • August 2008 (1)

Recent Comments

  • Kush on how to cakephp in a sub-directory, access it from root using .htaccess
  • Mr Griever on Access session data in a model -cakephp
  • apnarahimyarkhan on cakephp- CONCAT in query, Virtual Fields and make a drop down
  • Toko Kunci Pintu Murah on set & reset form text value onfocus, onblur, onclick using javascript
  • nevitaputri1.doodlekit on cakephp- CONCAT in query, Virtual Fields and make a drop down
  • RSS - Posts
  • RSS - Comments

Meta

  • Register
  • Log in
  • Entries feed
  • Comments feed
  • WordPress.com

Blog at WordPress.com.

Privacy & Cookies: This site uses cookies. By continuing to use this website, you agree to their use.
To find out more, including how to control cookies, see here: Cookie Policy
  • Follow Following
    • sarwar's weblogs
    • Join 328 other followers
    • Already have a WordPress.com account? Log in now.
    • sarwar's weblogs
    • Customize
    • Follow Following
    • Sign up
    • Log in
    • Report this content
    • View site in Reader
    • Manage subscriptions
    • Collapse this bar
%d bloggers like this: