mod_rewrite

Events happening in the community are now at Drupal community events on www.drupal.org.
hakan kristiansen's picture

Hej , Är det någon som kan förklara på ett enkelt sätt hur jag aktiverar "mod_rewrite" i apache konfigurationsfil?
Det finns mycket skrivet i manualer, men inget som är lätt att förstå.

Namn på filen och var hittar jag den?
Hur skall koden se ut?
Finns det fler filer som jag behöver ändra i?

Jag kör Apache 2.2

Hälsningar
Håkan

Comments

Allra enklast är att du

solipsist's picture

Allra enklast är att du använder dig av den .htaccess-fil som medföljer Drupal. Man kan ställa in Apache att ignorera .htaccess-filer (då de innebär en prestandaförlust vid mycket trafik) men standard brukar vara att tillåta dem.

Rewrite kräver givetvis att mod_rewrite finns installerat. Hur du gör det finns beskrivet på många ställen. Om instruktioner du hittar verkar svårtolkade, klistra in dem här så kan säkert någon av oss förklara dem.


Jakob Persson
imBridge - www.imbridge.com

Hej, Inklippt från htaccess

hakan kristiansen's picture

Hej,
Inklippt från htaccess filen:
Min sida ligger lokalt på min dator http://localhost/minweb/
Så vilket i texten nedan gäller mig?
Mvh H

RewriteEngine on

# If your site can be accessed both with and without the 'www.' prefix, you
# can use one of the following settings to redirect users to your preferred
# URL, either WITH or WITHOUT the 'www.' prefix. Choose ONLY one option:
#
# To redirect all users to access the site WITH the 'www.' prefix,
# (http://example.com/... will be redirected to http://www.example.com/...)
# adapt and uncomment the following:
# RewriteCond %{HTTP_HOST} ^example.com$ [NC]
# RewriteRule ^(.)$ http://www.example.com/$1 [L,R=301]
#
# To redirect all users to access the site WITHOUT the 'www.' prefix,
# (http://www.example.com/... will be redirected to http://example.com/...)
# uncomment and adapt the following:
# RewriteCond %{HTTP_HOST} ^www.example.com$ [NC]
# RewriteRule ^(.
)$ http://example.com/$1 [L,R=301]

# Modify the RewriteBase if you are using Drupal in a subdirectory or in a
# VirtualDocumentRoot and the rewrite rules are not working properly.
# For example if your site is at http://example.com/drupal uncomment and
# modify the following line:
# RewriteBase /drupal
#
# If your site is running in a VirtualDocumentRoot at http://example.com/,
# uncomment the following line:
# RewriteBase /

# Rewrite URLs of the form 'x' to the form 'index.php?q=x'.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]

Du behöver inte ändra

TBarregren's picture

Du behöver inte ändra något i .htaccess-filen för att få igång rewrite. Rader med # framför är kommentarer, och följaktligen är det endast följande som läses in av Apache:

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]

Men för att detta skall ha någon effekt måste Apaches modul mod_rewrite vara påslagen. Den slås på genom att på lämpligt ställe lägga en snarlik rad:

LoadModule rewrite_module /usr/lib/apache2/modules/mod_rewrite.so

Så vad innebär lämpligt ställe? På Debian baserade distributioner av Linux, som t.ex. Ubuntu, finns raden redan i filen /etc/apache2/mods-available/rewrite.load och det enda du behöver göra är att skapa en symbolisk länk till denna fil från /etc/apache2/mods-enabled/rewrite.load. Det gör du enklast med a2enmod rewrite. Du måste också ladda om konfigurationsfilerna med /etc/init.d/apache2 force-reload. I andra Linux distributioner, på Mac och Windows gör man på annat sätt. Som regel lägger man till (eller tar bort kommentartecknet # framför) den aktuella raden i httpd.conf-filen.

Och vad innebär snarlik rad? Du skall byta ut /usr/lib/apache2/modules/mod_rewrite.so mot den absoluta sökvägen till det delade bibliotek med mod_rewrite.

Lycka till! Och tveka inte att fråga mer här på [Drupal Sverige(http://www.drupalsverige.se) om du kör fast.


Thomas BarregrenimBridge

mod_rewrite

hakan kristiansen's picture

Tack Thomas för mycket bra handledning.

httpd.conf-filen i följande katalog "C:\apache2triad\conf" innehöll raden:
"LoadModule rewrite_module modules/mod_rewrite.so" och sökvägen stämmer bra överens till mod_rewrite

Dock löste det inte mitt problem med bilder och sökvägar på siten som inte fungerar.

Återstår att hitta andra infallsvinklar.

Tack för hjälpen
Mvh
Håkan

Sweden

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: