Jump to content
Larry Ullman's Book Forums

Recommended Posts

First, I've been pulling my hair trying to resolve this problem, I really would like to be able to have clean urls.

 

First I running on Windows 8 using XAMPP ( I now wish I was using Linux ).

 

I made sure that my .htaccess file does  indeed start with a period

 

Here the .access file

# Script 2.7 - .htaccess<IfModule mod_rewrite.c>
# Turn on the engine:RewriteEngine on
# Set the base to this directory:RewriteBase /chapter02/
# Redirect certain paths to index.php:RewriteRule 
^(about|contact|this|that|search)/?$ index.p
</IfModule>

here's the bottom of my httpd.conf file

# AJP13 Proxy<IfModule mod_proxy.c><IfModule 
mod_proxy_ajp.c>Include 
"conf/extra/httpd-ajp.conf"</IfModule></IfModule><Directory 
"c:/xampp/htdocs/php_test/chapter02"> AllowOverride 
All</Directory>

and here's part of my config.inc.php file

// Determine location of files and the URL of the site:// Allow for 
development on different servers.if ($local) {
    // Always debug when running 
locally:    $debug = 
TRUE;       // Define the 
constants:    define('BASE_URI', 
'c:/xampp/htdocs/php_test/chapter02');    define('BASE_URL', 
'http://localhost/php_test/chapter02/');    define('DB', 
'/path/to/mysql.inc.php');   } else {
    define('BASE_URI', 
'/path/to/live/html/folder/');    define('BASE_URL', 
'http://www.example.com/');    define('DB', 
'/path/to/live/mysql.inc.php');   }

Like I said I've been pulling my hair out, stopping apache server, restarting it, modifying code, restarting (even rebooting my machine once). I even did a Google search trying various "fixes" and even this forum. Any help would be greatly appreciated.

 

I know it is probably something stupid that I'm doing.

 

Best Regards,

            John

Share this post


Link to post
Share on other sites

You include a lot of details, which is great, except for what the problem is. I suspect you need to set your RewriteBase to /php_test/chapter02/

Share this post


Link to post
Share on other sites

Thanks for the help, but that wasn't it. I think I will move on and revisit this some other time, I also suspect I'll have no problems (I hope) doing this on the web server when the time comes. I now wish I would had built a linux base computer or made it a dual boot system.  Once again thanks. 

Share this post


Link to post
Share on other sites

Welcome to the forums, Strider64.

 

As Larry stated, you provided a lot of code, but didn't really explain what the problem is.

Are you getting an error, or is it just not working?

 

Whenever I am learning a new topic, I try to keep things as simple as possible. When dealing with regexes, all sorts of issues can pop up. As such, for your first mod_rewrite script, I recommend taking the regexes out of the equation, and just dealing with the mod_rewrite syntax/fundamentals.

 

For example, try to write a sample mod_rewrite script that redirects visitors going to a.html to b.html. By using two simple constants like that (without any regexes), you will hopefully be able to better isolate the problem and resolve it.

 

Good luck.

Share this post


Link to post
Share on other sites

Tip - "Once you adopt this system, you want to change the URLs for the links (in the HTML) and the action attribute form of the search form".

 

 

It felt like I read this over a thousand times in the book and it just didn't seem to click, man do I feel stupid. Needless to say it pays to really really pay attention to the details. I try to keep things simple as possible when I coding, but I have in the past spent time fixing the stupidest mistakes sometimes, I once spent a whole day a long time ago trying to figure out why my code wouldn't work. The problem was instead of having <?php I just had <?. I sometimes tend to have a hard time explaining, that's probably why I put too much code and I have visited other boards where people put to little code. I guess I will eventually find a happy medium  the next time.  :D   I got it working and thanks once again for all the help - the both of you. 

Share this post


Link to post
Share on other sites

Hi,

 

I added the below code in httpd.conf

++++++++++++++++++++++++++++++++++++++++++++

<Directory "C:/xampp/htdocs/php-oops/chp02">
AllowOverride All
Require all granted
</Directory>
 
 
my htaccess file is like this
++++++++++++++++++++++++++++++++++++++++++++
# Script 2.7 - .htaccess
<IfModule mod_rewrite.so>
# Turn on the engine:
RewriteEngine on
# Set the base to this directory:
RewriteBase /php-oops/chp02/
# Redirect certain paths to index.php:
RewriteRule ^(about|contact|this|that|search)/?$ index.php?p=$1
</IfModule>
 
Still not able to get the url rewrite working? xampp-httpd.conf?
 
Thanks in advance
sharma
 

Share this post


Link to post
Share on other sites

Hi Larry & other helpful members.

 

I sorted this problem. By removing 

#<IfModule mod_rewrite.so>

and <Ifmodule> these lines

in .htaccess.

 

I am checking why the <ifmodule> condition is not working in .htaccess..

if you have a handy answer/point please let me know.

 

Thanks,

sharma

Share this post


Link to post
Share on other sites

Finally I catch the error with ifmodule..

 

http://www.askapache.com/htaccess/htaccess-for-webmasters.html

<IfModule> should be<ifModule> if should be in small letters

 

#<IfModule mod_rewrite.so>

<ifModule mod_rewrite.c>
# Turn on the engine:
RewriteEngine on
# Set the base to this directory:
RewriteBase /php-oops/chp02/
# Redirect certain paths to index.php:
RewriteRule ^(about|contact|this|that|search)/?$ index.php?p=$1
</ifModule>
#</IfModule>
 
Thanks Larry..
I love all your great work and way of writing/teaching.
Your books made me proud after 10years of software developement.
Now I am enjoying Programming more than before..
 
sharma

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...