> > Topic

Using SEF / Clean Urls

Oct 23, 2006 / pixtur
Jan 5, 2009 / phsouzacruz
 

Attached files

No files uploaded
 

Enable clean urlsπ

Since v0.075 Streber supports Clean urls using the Apache module ´mod_rewrite´. To use clean urls you have to:
  • make sure mod_rewrite is installed on your server. For this you can click on the footer Link system info. And then view the phpInfo() output. Under the section ApacheXHandler make sure that Loaded Modules includes mod_rewrite.
  • make sure that the .htaccess-files are supported by your provider. In the httpd.conf this option is listed like:
    #
    # 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
  • add the following line to your customize.inc.php:
confChange('USE_MOD_REWRITE', true);

What's the differenceπ

Most streber urls look like...

 http://streber.pixtur.de/index.php?go=taskView&tsk=589

Since in streber all items have unique ids, this number is the only thing we need to display this task. If mod_rewrite is been used, all urls will be generated like...

 http://streber.pixtur.de/589

Slightly more readable. This will also decrease html code size and speed up download of your html pages.

Warning / Performanceπ

You should note, that using mod_write in subdirectories via .htaccess can be really slow.

pixtur noticed that on this server (hosted by http://www.all-inkl.com) the usage of SEF-Urls is fast only for subdomains (e.g. http://streber.pixtur.de) but not for subdirectories (e.g. http://www.pixtur.de/some_directory). In subdirectories this caused an inacceptable delay of 2 - 4 seconds.
You should test this.




also see:

5 Comments

ramsay:This works in lighttpd also

11 years ago

For this to work in lighttpd, you need to enable mod_rewrite in your lighttpd.conf. Then the following code snippet will do the proper rewriting:

from lighttpd.conf

url.rewrite-once += (
  "^/streber/([0-9]+)$" => "/streber/index.php?go=itemView&id=$1",
  "^/streber/([a-zA-Z]+)$" => "/streber/index.php?go=globalView&id=$1" )

If you do not access your streber install at myhost.com/streber/ you will need to edit this appropriately to reflect your changed directory names.

dequid:Switching to mod_rewrite does not work and breaks my streber installation

10 years ago (2. update 10 years ago)

I tried to enable mod_rewrite for my streber installation (0.08)
on a virtualhost under apache 2.
I followed above steps, and streber-links are build correctly
as http://streber.foo.net/14 for example, but clicking the link
results in a 404 error.

My virtualhost .conf looks like this:

<VirtualHost *:80>

        ServerName   streber.foo.net
        DocumentRoot /var/www/streber.foo.net
        ErrorLog     /var/www/streber.foo.net/error.log
        CustomLog    /var/www/streber.foo.net/access.log combined

        <Directory /var/www/streber.foo.net>

            AllowOverride All
            DirectoryIndex index.php
            Options +ExecCGI -Indexes

            Order allow,deny
            Allow from all

        </Directory>

</VirtualHost>

As i tried to switch off mod_rewrite again by commenting out confChange('USE_MOD_REWRITE', true);
clicking _any_ link will result in logging out the current user with the message:
'Cookie is no longer valid for this computer.'
Logging in again works, but only for 1 view. Following any link will lead again to
the login mask with the same message. Another side effect is that images (and thumbnails)
are not displayed any more.

Anybody got an idea what i have missed or what i can do to either get SEF urls to work
or get my streber working again with plain old ugly urls.

Any help is very appreciated.

dequid:Problem fixed

10 years ago

In case, anyone stumbles into the same problem, i got it working.

Problem 1 was:
necessary .htaccess for applying the rewrite rules was not
part of the current streber distribution (v0.08) :)
This is fixed now i guess.

Problem 2 "Logs-me-out-Problem":
If you use webdeveloper-toolbar for firefox: cookies > delete domain/path cookies seems not to work as expected. I had to clear them manually in my firefox preferences, so i was able
to log into streber again.

Have fun.

axelle:Répondre Problem fixed

10 years ago

Hi,

you said .htaccess file was missing in streber v0.08
where did you find it then?

thanks.

dequid:Reply to Problem fixed

10 years ago

got it from pixtur :)

Actually, it has to look like this:

RewriteEngine on
RewriteRule ^([0-9]+)$ index.php?go=itemView&id=$1 [L]
RewriteRule ^([a-zA-Z]+)$ index.php?go=globalView&id=$1 [L]

ErrorDocument 400 /streber/index.php
ErrorDocument 401 /streber/index.php
ErrorDocument 403 /streber/index.php
ErrorDocument 404 /streber/index.php
ErrorDocument 500 /streber/index.php