Back to the main site

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.

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”! If after doing this, the nice url feature still doesn't work, or you experience unaccessible, 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/dokuwiki>
  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]
...
  • 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: 2008/07/07 20:29 (external edit)
 
Recent changes RSS feed Creative Commons License Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki