[mod_rewrite] weiterleitung auf die richtige URL

02.09.2012 21:22 Uhr

Hallo, mein CMS produziert merkwürdige URLs - die ins nirvana führen. 

Ein Beispiel: domain.com/category/mein-artikel-ganz-toll/forward/234552

Das Problem dabei, das die URL wirklich existiert, wenn das forward/234552 weg genommen wird kann der Artikel ganz normal aufgerufen werden. 

Da ich den Fehler im CMS einfach nicht finde, würde ich mich über eine Lösung mit .htaccess freuen. Sprich das "forward/234552 sollte nicht beachtet werden, falls ihr versteht was ich damit meine

Optimalerweise sollte es eine 301er Rule werden.

5 Antworten

#1

03.09.2012 08:16 Uhr

Hallo,

generell wäre es natürlich cooler wenn dein CMS die richtigen URLs erzeugt ;)

Mit dem mod_rewrite könnte es vllt so funktionieren (via askapache.com):

RewriteRule ^(.*)forward/\d+$ $1 [R=301,L]

Die Regel sollte aus dem:

domain.com/category/mein-artikel-ganz-toll/forward/234552

das machen:

domain.com/category/mein-artikel-ganz-toll/

 

#2

03.09.2012 09:34 Uhr

Danke Tim, nur funktioniert das leider nicht. Die Seite bleibt weiterhin einfach weiß :(

#3

03.09.2012 14:45 Uhr

Hmm, 

anbei meine .htaccess - bitte freundlich behandeln :)

 

<Files .htaccess>
	order allow,deny
	deny from all
</Files>

AddDefaultCharset UTF-8
php_flag register_globals off
Options +Indexes +FollowSymlinks
RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} !^www\.domain\.de$ [NC] 
RewriteRule ^(.*)$ http://www.domain.de/$1 [L,R=301] 
RewriteRule ^category/(.+)$ http://www.domain.de/$1 [R=301,L] 

ErrorDocument 404 /www/htdocs/w43576753/404error/
RewriteRule ^(cgi-bin|docs|pdf) - [L]

RewriteRule ^admin/?$ admin_index.php [L]
RewriteRule ^admin/([a-zA-Z0-9_-]+)/?$ admin_index.php?page=$1 [L]
RewriteRule ^admin/plugin/([a-zA-Z0-9_-]+)/?$ admin_index.php?page=plugin_settings&plugin=$1 [L]

RewriteRule \.(css|php|png|jpg|gif|pdf|ico|js|inc|txt|gz|xml|html|eot|otf|ttf|woff)$ - [NC,L]
RewriteRule ^([^/]*)/?$ index.php?page=$1 [L]
RewriteRule ^([^/]*)/([^/]*)/?$ index.php?$1=$2 [L]
RewriteRule ^([^/]*)/([^/]*)/([^/]*)/?$ index.php?page=$1&$2=$3 [L]
RewriteRule ^([^/]*)/([^/]*)/([^/]*)/([^/]*)/?$ index.php?$1=$2&$3=$4 [L]
RewriteRule ^([^/]*)/([^/]*)/([^/]*)/([^/]*)/([^/]*)/?$ index.php?page=$1&$2=$3&$4=$5 [L]
RewriteRule ^([^/]*)/([^/]*)/([^/]*)/([^/]*)/([^/]*)/([^/]*)/?$ index.php?$1=$2&$3=$4&$5=$6 [L]

<IfModule mod_gzip.c>
   mod_gzip_on yes
   mod_gzip_static_suffix .gz
   mod_gzip_can_negotiate yes
   AddEncoding gzip .gz
   mod_gzip_update_static no
   mod_gzip_item_include file \.(html|php|rss)$
   mod_gzip_item_exclude file \.(css|js|exe)$
   mod_gzip_item_exclude mime ^image/.*
   mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
   mod_gzip_dechunk yes
 </IfModule>

<IfModule mod_deflate.c>
  <FilesMatch "\.(css|js|xhtml|html|htm|php)$">
	SetOutputFilter DEFLATE
	AddOutputFilterByType DEFLATE text/plain
    AddOutputFilterByType DEFLATE text/html
    AddOutputFilterByType DEFLATE text/xml
    AddOutputFilterByType DEFLATE text/css
    AddOutputFilterByType DEFLATE text/javascript
    AddOutputFilterByType DEFLATE application/xml
    AddOutputFilterByType DEFLATE application/xhtml+xml
    AddOutputFilterByType DEFLATE application/rss+xml
    AddOutputFilterByType DEFLATE application/javascript
    AddOutputFilterByType DEFLATE application/x-javascript
    AddOutputFilterByType DEFLATE application/x-shockwave-flash
  </FilesMatch>
</IfModule>

<IfModule mod_expires.c>
    # turn on the module for this directory
    ExpiresActive on
    # set default
    ExpiresDefault "access plus 24 hours"
    ExpiresByType image/jpg "access plus 1 months"
    ExpiresByType image/gif "access plus 1 months"
    ExpiresByType image/jpeg "access plus 1 months"
    ExpiresByType image/png "access plus 1 months"
    ExpiresByType text/css "access plus 1 months"
    ExpiresByType text/javascript "access plus 1 months"
    ExpiresByType application/javascript "access plus 1 months"
    ExpiresByType application/x-shockwave-flash "access plus 1 months"
</IfModule>

<IfModule mod_headers.c>
  <FilesMatch "\\.(eot|svg|svgz|ttf|woff|ico|jpeg|jpg|png|gif|swf)$">
	Header set Cache-Control "max-age=4592000, public"
	Header set Last-Modified "Mon, 03 Jan 2012 00:00:00 GMT"
  </FilesMatch>
  <FilesMatch "\\.(css)$">
	Header set Cache-Control "max-age=604800, public"
	Header set Last-Modified "Mon, 03 Jan 2012 00:00:00 GMT"
  </FilesMatch>
  <FilesMatch "\\.(js)$">
	Header set Cache-Control "max-age=4592000, private"
	Header set Last-Modified "Mon, 03 Jan 2012 00:00:00 GMT"
  </FilesMatch>
  <FilesMatch "\\.(xhtml|html|htm|php)$">
	Header set Cache-Control "max-age=600, private, must-revalidate"
	Header set Last-Modified "Mon, 09 Apr 2012 00:00:00 GMT"
  </FilesMatch>
</IfModule>

<IfModule mod_headers.c>
  Header unset ETag
</IfModule>
FileETag None

<IfModule mod_headers.c>
  Header unset Last-Modified
</IfModule>

#4

04.09.2012 11:10 Uhr

Da du ja so einige mod_rewrite-Rules nutzt, sollte es mit dieser eigentlich kein Problem geben.

Versuch es doch mal alternativ mit dieser hier, das sollte dasselbe bewirken:

RewriteRule ^(.*)forward/([0-9]+)$ $1 [R=301,L]

 

Am besten direkt nach der Definition deiner Standard-Domain einfügen.
Evtl. musst du auch, wie bereits bei den "category"-Redirects die ganze URL nutzen: 

RewriteRule ^(.*)forward/([0-9]+)$ http://www.domain.de/$1 [R=301,L]

 

Kommt weiterhin ein weißer Screen, dann nenne uns doch bitte mal den http-Statuscode der produziert wird.

 

#5

04.09.2012 11:46 Uhr

Danke Jan, 

merkwürdig. Auch dies funktioniert nicht - einen Statuscode gibts es auch nicht. 

Habe die URL nun mit einem Statustool geprüft, dabei kommt folgendes raus:

 

#1 Server Response: http://www.domain.de/category/mein-artikel/forward/312/
HTTP/1.1 302 Found Date: Tue, 04 Sep 2012 10:44:35 GMT Server: Apache X-Powered-By: PHP/5.3.13-nmm1 Set-Cookie: PHPSESSID=87f760cbb30a483065f90a437b777e94; path=/ Expires: Thu, 19 Nov 1981 08:52:00 GMT Cache-Control: max-age=600, private, must-revalidate Pragma: no-cache Location: http:// Vary: Accept-Encoding Last-Modified: Mon, 09 Apr 2012 00:00:00 GMT Content-Type: text/html; charset=UTF-8

Ähnliche Fragen



Datenschutzerklärung · Impressum