Noah's Classifieds
 
Noah's Documentation
 

Nice URL feature

Noah's Classifieds supports using nice URLs. This means for example that the link of an ad details page can look like this:

  http://your.classifieds.site/item/10
  

instead of the conventional URL:

  http://your.classifieds.site/index.php?item/10
  

Besides that the former one is nicer, it is also said to be more search engine friendly.

Enabling the Nice URL feature

Rewriting URLs in Apache is done through the mod_rewrite module of Apache 1 or Apache 2. If you click on the Check menu point as admin and the RewriteEngine is not yet enabled, the configuration script attempts to find out whether the rewrite module is available at all. In some cases, this can't be detected for sure (especially if Php is installed as a CGI binary).

The rewrite module is enabled in httpd.conf with the following line (make sure it is not commented out):

LoadModule rewrite_module modules/mod_rewrite.so

If the rewrite module is available, you should have a file under the classifieds installation directory called .htacces with the following content in it, in order to enable nice URLs:

<IfModule mod_rewrite.c>
  RewriteEngine on
  RewriteRule .* - [env=REWRITE_ON:1]
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteRule ^(.*)$ index.php?url=$1 [L]
</IfModule>

Note that Noah's Classifieds is actually installed with this default .htaccess, so in most of the cases, the nice URL feature must work “out of the box”!

Troubleshooting

Inaccessible pages

If you experience inaccessible, forbidden, or in other ways destructed pages, you should also check the following:

  • .htaccess override for the classifieds webroot must be enabled. To enable it try adding the following to the httpd.conf:
<Directory /path/to/noah>
  AllowOverride All
</Directory>
  • FollowSymLinks for the classifieds webroot is enabled. Put the following in .htaccess:
Options +FollowSymlinks
RewriteEngine on
 
...etc.
  • If you get Error 400 pages, you can try to add a RewriteBase to the .htaccess file. On the line RewriteBase /noah, you need to replace the /noah with whatever directory you use in your URL to get to the program. Say that your normal URL is http://www.whatever.com/projects/classifieds/index.php . You will need to set the below line to RewriteBase /projects/classifieds.
RewriteEngine on
RewriteBase /noah
  • If you're running without a RewriteBase, perhaps because you're hosting under a dedicated VirtualHost, and you still get Error 400 pages, try to modify the rewrite rules the following way:
...
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /index.php?url=$1 [L]
...

mod_rewrite is available, but the program can't detect that it is enabled

There was one more strange case when the mod_rewrite was actually available on a server and usable, but the program still “thought” so that it is not enabled (and therefore generated the conventional URLs). If was caused by that the following line in the .htaccess file - from whatever reason - couldn't pass the information that mod_rewrite is enabled to the program:

  RewriteRule .* - [env=REWRITE_ON:1]

We don't know the reason why it happens (probably because this way of setting environment variables is disabled in the global Apache configuration), but if you suspect that this happens, you can use the following workaround: add this line into 'app/config.php: $_SERVER[“REWRITE_ON”]=1; (so the end of the file should look like this):

...
$_SERVER["REWRITE_ON"]=1;
?>

This tells the program that the mod_rewrite is enabled whatever comes from the .htaccess file.

Blank pages

In case of sites where Php is installed as a CGI module, it can happen that you get blank pages. Try to insert the following line into 'app/constants.php' to fix this:

$_SERVER["QUERY_STRING"] = $_SERVER["REDIRECT_SCRIPT_URL"];

Notes

  • And what if it still doesn't work even you tried everything? Well, at this point, you will probably feel so that those conventional URLs are not so ugly anyway! :-)
  • The rewrite rules given above will map all non-existing files and directories to the Noah's index.php, this may apply to virtual mappings (aliases), too. Eg. some hosters map web access statistics to a virtual /stats directory. To be able to still access these virtual dirs you need to exclude them in the rewrite conditions. Example:
...
RewriteCond %{REQUEST_FILENAME}       !-d
RewriteCond %{REQUEST_FILENAME}       !-f
RewriteCond %{REQUEST_URI} !^/stats/(.*)$
...
 
configuration/rewriterules.txt · Last modified: 2009/06/30 10:32 (external edit)