httpd-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Johannes Bauer <dfnsonfsdu...@gmx.de>
Subject [users@httpd] Problem with mod_rewrite
Date Fri, 31 Jan 2014 15:56:18 GMT
Hi list,

I'm currently having some trouble with Apache 2.2.25 running in
conjunction with PHP 5.4.4. It's running a blog software (b2evolution).
Please don't judge me, it's not my blog :-) Anyways, permalinks to the
blog previously looked like this:

http://www.myserver.com/blog5.php/this-is-a-permalink

Now I've changed around the server config so they're more generic
(ultimately I want to move away from PHP). Now they look like this:

http://www.myserver.com/blog/this-is-a-permalink

To get this working, I had issued a mod_redirect directive in the
Directory section for the relevant vhost:

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f	
RewriteCond %{REQUEST_URI} ^/blog/[-a-zA-Z0-9]+$
RewriteRule ^blog/([-a-zA-Z0-9]+)$ blog/index.php/$1 [L,QSA]

Now when an access occurs to /blog/this-is-a-permalink it works nicely
and this is the mod_redirect log output I get:

strip per-dir prefix: /var/www/myserver.com/blog/this-is-a-permalink ->
blog/this-is-a-permalink
applying pattern '^blog/([-a-zA-Z0-9]+)$' to uri 'blog/this-is-a-permalink'
rewrite 'blog/this-is-a-permalink' -> 'blog/index.php/this-is-a-permalink'
add per-dir prefix: blog/index.php/this-is-a-permalink ->
/var/www/myserver.com/blog/index.php/this-is-a-permalink
strip document_root prefix:
/var/www/myserver.com/blog/index.php/this-is-a-permalink ->
/blog/index.php/this-is-a-permalink
internal redirect with /blog/index.php/this-is-a-permalink [INTERNAL
REDIRECT]
add path info postfix: /var/www/myserver.com/blog/index.php ->
/var/www/myserver.com/blog/index.php/this-is-a-permalink
strip per-dir prefix:
/var/www/myserver.com/blog/index.php/this-is-a-permalink ->
blog/index.php/this-is-a-permalink
applying pattern '^blog/([-a-zA-Z0-9]+)$' to uri
'blog/index.php/this-is-a-permalink'
pass through /var/www/myserver.com/blog/index.php
strip per-dir prefix: /var/www/myserver.com/this-is-a-permalink ->
this-is-a-permalink
applying pattern '^blog/([-a-zA-Z0-9]+)$' to uri 'this-is-a-permalink'
pass through /var/www/myserver.com/this-is-a-permalink

This is how it looks on the client side:

> GET /blog/this-is-a-permalink HTTP/1.1
> User-Agent: curl/7.31.0
> Host: www.myserver.com
> Accept: */*
>
< HTTP/1.1 200 OK
< Date: Fri, 31 Jan 2014 15:46:43 GMT
* Server Apache is not blacklisted
< Server: Apache
< X-Powered-By: PHP/5.4.4-14+deb7u7
< Set-Cookie:
session_b2evo__myserver.com=493300_m2Z3cuWzhm3x72ss39ylCdUdSNBgK9Ky;
expires=Mon, 29-Jan-2024 15:46:43 GMT; path=/; domain=.myserver.com
< Expires: Fri, 31 Jan 2014 15:46:43 +0000
< Last-Modified: Fri, 31 Jan 2014 15:46:43 +0000
< Cache-Control: no-cache, must-revalidate
< Pragma: no-cache
< Vary: Accept-Encoding
< Transfer-Encoding: chunked
< Content-Type: text/html; charset=ISO-8859-1


For compatibility, however, I'd like to also support a redirection to
the old style links (for people who still have bookmarks). Therefore I
introduced the analogous commands:

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} ^/blog5.php/[-a-zA-Z0-9]+$
RewriteRule ^blog5.php/([-a-zA-Z0-9]+)$ blog/index.php/$1 [L,QSA]

This isn't working at all, however:

add path info postfix: /var/www/myserver.com/blog5.php ->
/var/www/myserver.com/blog5.php/this-is-a-permalink
strip per-dir prefix:
/var/www/myserver.com/blog5.php/this-is-a-permalink ->
blog5.php/this-is-a-permalink
applying pattern '^blog5.php/([-a-zA-Z0-9]+)$' to uri
'blog5.php/this-is-a-permalink'
rewrite 'blog5.php/this-is-a-permalink' ->
'blog/index.php/this-is-a-permalink'
add per-dir prefix: blog/index.php/this-is-a-permalink ->
/var/www/myserver.com/blog/index.php/this-is-a-permalink
strip document_root prefix:
/var/www/myserver.com/blog/index.php/this-is-a-permalink ->
/blog/index.php/this-is-a-permalink
internal redirect with /blog/index.php/this-is-a-permalink [INTERNAL
REDIRECT]
add path info postfix: /var/www/myserver.com/blog/index.php ->
/var/www/myserver.com/blog/index.php/this-is-a-permalink
strip per-dir prefix:
/var/www/myserver.com/blog/index.php/this-is-a-permalink ->
blog/index.php/this-is-a-permalink
applying pattern '^blog5.php/([-a-zA-Z0-9]+)$' to uri
'blog/index.php/this-is-a-permalink'
add path info postfix: /var/www/myserver.com/blog/index.php ->
/var/www/myserver.com/blog/index.php/this-is-a-permalink
strip per-dir prefix:
/var/www/myserver.com/blog/index.php/this-is-a-permalink ->
blog/index.php/this-is-a-permalink
applying pattern '^blog/([-a-zA-Z0-9]+)$' to uri
'blog/index.php/this-is-a-permalink'
pass through /var/www/myserver.com/blog/index.php
strip per-dir prefix: /var/www/myserver.com/this-is-a-permalink ->
this-is-a-permalink
applying pattern '^blog5.php/([-a-zA-Z0-9]+)$' to uri 'this-is-a-permalink'
strip per-dir prefix: /var/www/myserver.com/this-is-a-permalink ->
this-is-a-permalink
applying pattern '^blog/([-a-zA-Z0-9]+)$' to uri 'this-is-a-permalink'
pass through /var/www/myserver.com/this-is-a-permalink

And on the client side:

> GET /blog5.php/this-is-a-permalink HTTP/1.1
> User-Agent: curl/7.31.0
> Host: www.myserver.com
> Accept: */*
>
< HTTP/1.1 301 Moved Permanently
< Date: Fri, 31 Jan 2014 15:52:37 GMT
* Server Apache is not blacklisted
< Server: Apache
< X-Powered-By: PHP/5.4.4-14+deb7u7
< Set-Cookie:
session_b2evo__myserver.com=493307_xsaMBDcHXQKGUBYmgDB3vDXUcBJtINRe;
expires=Mon, 29-Jan-2024 15:52:37 GMT; path=/; domain=.myserver.com
< Location: http://www.myserver.com/blog/
< Vary: Accept-Encoding
< Content-Length: 0
< Content-Type: text/html; charset=ISO-8859-1

So ultimately I think the initial redirect is working (at one point it
actually says blog/index.php/this-is-a-permalink) and it's passing it
through the blog's index.php, but then apparently some weird additional
redirection happens which ultimately sends it to /this-is-a-permalink
(which is a 404 and therefore apparently translated into a 301 to the
blogs default page).

I must admit that this really puzzles me, but I am really also not too
sure that I'm using mod_redirect appropriately. If you know what's wrong
and could help me I'd be forever grateful. Thank you very much in advance,

Best regards,
Johannes

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Mime
View raw message