Jump to content
Larry Ullman's Book Forums

Enabling Url Rewriting Not Working


Recommended Posts

I have added the following line from the book to httpd.conf

 

<Directory "C:/xampp/htdocs/php_advanced/ch02">

AllowOverride All

</Directory>

 

In the httpd.conf my modrewrite line is as follows:

 

LoadModule rewrite_module modules/mod_rewrite.so

 

In the book it showed mod_rewrite.so as mod_rewrite.c, well mine has an extension of ".so" not ".c", so i changed the .htaccess file to be:

 

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

 

However when i run the script and clink on the link going to the about.php script http://localhost/php...dex.php?p=about the URL is not rewritten to http://localhost/php...ced/ch02/about.

 

Does anyone have any suggestions on why this may not be working?

Link to comment
Share on other sites

Isn't it the other way around?

I mean, shouldn't the link in your HTML file be "http://localhost/php_advanced/ch02/about", not "http://localhost/php_advanced/ch02/index.php?p=about"?

 

I think you're supposed to write the links the way you want them to look in your HTML.

When a user clicks on a link, the rewrite rule should be implemented, which will lead the user to the actual page (without them knowing about it).

 

That seems to be the problem to me, but please verify that.

  • Upvote 2
Link to comment
Share on other sites

Yes you are right. But even when i put the link http://localhost/php...nced/ch02/about into the browser i got an error message back

 

Object not found!
The requested URL was not found on this server. If you entered the URL manually please check your spelling and try again.
If you think this is a server error, please contact the webmaster.
Error 404
localhost
Apache/2.4.3 (Win32) OpenSSL/1.0.1c PHP/5.4.7

 

I also tried changing the link within the HTML to "about" and it still didn't work. It looks like the rewrite is not enabled but i don't know!

Link to comment
Share on other sites

Here are the partial contents of my httpd.conf file:

 

LoadModule rewrite_module modules/mod_rewrite.so

DocumentRoot "C:/xampp/htdocs"

<Directory />
AllowOverride none
Require all denied
</Directory>

<Directory "C:/xampp/htdocs">
#
# Possible values for the Options directive are "None", "All",
# or any combination of:
# Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
#
# Note that "MultiViews" must be named *explicitly* --- "Options All"
# doesn't give it to you.
#
# The Options directive is both complicated and important. Please see
# http://httpd.apache.org/docs/2.2/mod/core.html#options
# for more information.
#
Options Indexes FollowSymLinks Includes ExecCGI

#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# Options FileInfo AuthConfig Limit
#
AllowOverride All

#
# Controls who can get stuff from this server.
#
Require all granted

</Directory>

 

Tried moving files into the localhost root directory with the .htaccess file but still no luck. Checked online and can't figure it out, I already have AllowOverride All set and that was the common solution to the problem.

Link to comment
Share on other sites

Sorry, Edward, but I'm not going to study the contents of the entire httpd.conf file to help you.

On a more practical level, you may want to trim all that code out of your previous post, as it makes this thread take a while to load.

 

Anyway, you may want to test mod_rewrite with a simple example at first, just to make sure that it is indeed the engine, and not your regex/code, that's the problem.

For example, you might want to try a mod_rewrite rule like the following:

 

RewriteRule a.php b.php

 

If something simple like that doesn't work, then we can go from there.

  • Upvote 2
Link to comment
Share on other sites

Lol so funny the script is actually 5 vertical scrolls on my galaxy note. Lol this script will be burning up some serious weight on larrys host. Okay when i get back home ill trim it. I'll try your suggestion this is what i was thinking that htaccess may be completely being ignored.

Link to comment
Share on other sites

Friday, 26 October 2012, 11:14:05 JST

Description: Passing clouds. Mild. Temperature: 20 °C Comfort Level: 20 °C Wind: 11 km/h from 10° Northsa16.png Last update: Fri 10:00 JST

 

Yes i got the same error message coming up even with your suggestion,

Object not found!

 

The requested URL was not found on this server. If you entered the URL manually please check your spelling and try again.

If you think this is a server error, please contact the webmaster.

Error 404

localhost

Apache/2.4.3 (Win32) OpenSSL/1.0.1c PHP/5.4.7

Link to comment
Share on other sites

Okay i moved the scripts into the root now htdocs folder. So the AllowOverride All was now automatically set by default in the script. I have put the original version of my script back up. Yes i am using the newest download of XAMPP 1.8.1.

 

I see you are +2hrs GMT of me, i may come over there and visit you one of these days, never been to Japan before. But this New Years i am going to Hong Kong, so i will come next year sometime.

Link to comment
Share on other sites

Ah, the missing period. That's annoying.

 

I had a recent error that was similar in nature and driving me crazy:

 

I have a Japanese keyboard, and while I was writing some PHP one day, my hand slipped and I ended up writing an ending PHP tag (?>) in Japanese mode, not English mode.

For a variety of boring reasons that I don't want to go into here, the Japanese version of ?> looks identical to the English ?> in my text editor, even though the actual characters are different.

 

Anyway, I tried running the script in my browser, and I kept getting an error, and for the life of me, I couldn't figure out why. It wasn't until, out of desperation, I erased the whole line and rewrote it from scratch and it worked did it dawn on me what the problem was.

 

Anyway, those types of errors are really hard to catch, and they're really hard for us to diagnose on a message board too.

 

Kudos on solving your particular problem though.

Sleep well!

  • Upvote 1
Link to comment
Share on other sites

Yes it was the kind of error that can be easily overlooked even though we are aware of common debugging techniques. Larry this is a small meesage to you please check the download code for htaccess file chap2.

 

Despite of what happened i am happy with the way this has turned out, mod rewrite has been something i wanted to do for a long time its awesome. Its funny did you ever see ebay or amazon tidy up their urls.

Link to comment
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...
 Share

×
×
  • Create New...