Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm trying to get a mod rewrite to work, currently I get 404s.

Here's the rule :

Options +FollowSymlinks
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f

RewriteRule ^/portfolio/([\w-]+)$ `index.php?portfolio=$1`

I input example.com/portfolio/derp and get a 404 when I want index.php?portfolio=derp.

Here's the rewrite log file :

[www.example.com/sid#9d9d4b0][rid#9fdb898/initial] (3) [perdir /var/www/html/] add path info postfix: /var/www/html/portfolio -> /var/www/html/portfolio/derp
[www.example.com/sid#9d9d4b0][rid#9fdb898/initial] (3) [perdir /var/www/html/] strip per-dir prefix: /var/www/html/portfolio/derp -> portfolio/derp
[www.example.com/sid#9d9d4b0][rid#9fdb898/initial] (3) [perdir /var/www/html/] applying pattern '^' to uri 'portfolio/derp'
[www.example.com/sid#9d9d4b0][rid#9fdb898/initial] (4) [perdir /var/www/html/] RewriteCond: input='off' pattern='!=on' => matched
[www.example.com/sid#9d9d4b0][rid#9fdb898/initial] (4) [perdir /var/www/html/] RewriteCond: input='www.example.com' pattern='^www\.(.+)$' [NC] => matched
[www.example.com/sid#9d9d4b0][rid#9fdb898/initial] (2) [perdir /var/www/html/] rewrite 'portfolio/derp' -> 'http://example.com/portfolio/derp'
[www.example.com/sid#9d9d4b0][rid#9fdb898/initial] (2) [perdir /var/www/html/] explicitly forcing redirect with http://example.com/portfolio/derp
[www.example.com/sid#9d9d4b0][rid#9fdb898/initial] (1) [perdir /var/www/html/] escaping http://example.com/portfolio/derp for redirect
[www.example.com/sid#9d9d4b0][rid#9fdb898/initial] (1) [perdir /var/www/html/] redirect to http://example.com/portfolio/derp [REDIRECT/301]
[example.com/sid#9d9d4b0][rid#9fdb898/initial] (3) [perdir /var/www/html/] add path info postfix: /var/www/html/portfolio -> /var/www/html/portfolio/derp
[example.com/sid#9d9d4b0][rid#9fdb898/initial] (3) [perdir /var/www/html/] strip per-dir prefix: /var/www/html/portfolio/derp -> portfolio/derp
[example.com/sid#9d9d4b0][rid#9fdb898/initial] (3) [perdir /var/www/html/] applying pattern '^' to uri 'portfolio/derp'
[example.com/sid#9d9d4b0][rid#9fdb898/initial] (4) [perdir /var/www/html/] RewriteCond: input='off' pattern='!=on' => matched
[example.com/sid#9d9d4b0][rid#9fdb898/initial] (4) [perdir /var/www/html/] RewriteCond: input='example.com' pattern='^www\.(.+)$' [NC] => not-matched
[example.com/sid#9d9d4b0][rid#9fdb898/initial] (3) [perdir /var/www/html/] add path info postfix: /var/www/html/portfolio -> /var/www/html/portfolio/derp
[example.com/sid#9d9d4b0][rid#9fdb898/initial] (3) [perdir /var/www/html/] strip per-dir prefix: /var/www/html/portfolio/derp -> portfolio/derp
[example.com/sid#9d9d4b0][rid#9fdb898/initial] (3) [perdir /var/www/html/] applying pattern '^/portfolio/([\w-]+)$' to uri 'portfolio/derp'
[example.com/sid#9d9d4b0][rid#9fdb898/initial] (3) [perdir /var/www/html/] add path info postfix: /var/www/html/portfolio -> /var/www/html/portfolio/derp
[example.com/sid#9d9d4b0][rid#9fdb898/initial] (3) [perdir /var/www/html/] strip per-dir prefix: /var/www/html/portfolio/derp -> portfolio/derp
[example.com/sid#9d9d4b0][rid#9fdb898/initial] (3) [perdir /var/www/html/] applying pattern '(^|/)\.' to uri 'portfolio/derp'
[example.com/sid#9d9d4b0][rid#9fdb898/initial] (1) [perdir /var/www/html/] pass through /var/www/html/portfolio
[example.com/sid#9d9d4b0][rid#a010568/initial/redir#1] (3) [perdir /var/www/html/] strip per-dir prefix: /var/www/html/404.html -> 404.html
[example.com/sid#9d9d4b0][rid#a010568/initial/redir#1] (3) [perdir /var/www/html/] applying pattern '^' to uri '404.html'
[example.com/sid#9d9d4b0][rid#a010568/initial/redir#1] (4) [perdir /var/www/html/] RewriteCond: input='off' pattern='!=on' => matched
[example.com/sid#9d9d4b0][rid#a010568/initial/redir#1] (4) [perdir /var/www/html/] RewriteCond: input='example.com' pattern='^www\.(.+)$' [NC] => not-matched
[example.com/sid#9d9d4b0][rid#a010568/initial/redir#1] (3) [perdir /var/www/html/] strip per-dir prefix: /var/www/html/404.html -> 404.html
[example.com/sid#9d9d4b0][rid#a010568/initial/redir#1] (3) [perdir /var/www/html/] applying pattern '^/portfolio/([\w-]+)$' to uri '404.html'
[example.com/sid#9d9d4b0][rid#a010568/initial/redir#1] (3) [perdir /var/www/html/] strip per-dir prefix: /var/www/html/404.html -> 404.html
[example.com/sid#9d9d4b0][rid#a010568/initial/redir#1] (3) [perdir /var/www/html/] applying pattern '(^|/)\.' to uri '404.html'
[example.com/sid#9d9d4b0][rid#a010568/initial/redir#1] (1) [perdir /var/www/html/] pass through /var/www/html/404.html

Hope you can make sense of that. It could be written in Japanese as far as I'm concerned.

OK I've stripped down the .htaccess to just this :

RewriteEngine On
Options +FollowSymlinks

RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f


RewriteRule ^portfolio/([\w-]+)$ index.php?portfolio=$1

Removing the leading slash , this does load index.php but it looks for all the linked stuff pics , css stylesheet ect in /portfolio when they're in the root.

Here is the log for that rewrite :

   myip - - [11/Feb/2012:20:58:32 +0000] [mydomain.com/sid#840f4b0][rid#864d898/initial] (3) [perdir /var/www/html/] add path info postfix: /var/www/html/portfolio -> /var/www/html/portfolio/derp
myip - - [11/Feb/2012:20:58:32 +0000] [mydomain.com/sid#840f4b0][rid#864d898/initial] (3) [perdir /var/www/html/] strip per-dir prefix: /var/www/html/portfolio/derp -> portfolio/derp
myip - - [11/Feb/2012:20:58:32 +0000] [mydomain.com/sid#840f4b0][rid#864d898/initial] (3) [perdir /var/www/html/] applying pattern '^portfolio/([\w-]+)$' to uri 'portfolio/derp'
myip - - [11/Feb/2012:20:58:32 +0000] [mydomain.com/sid#840f4b0][rid#864d898/initial] (4) [perdir /var/www/html/] RewriteCond: input='/var/www/html/portfolio' pattern='!-d' => matched
myip - - [11/Feb/2012:20:58:32 +0000] [mydomain.com/sid#840f4b0][rid#864d898/initial] (4) [perdir /var/www/html/] RewriteCond: input='/var/www/html/portfolio' pattern='!-f' => matched
myip - - [11/Feb/2012:20:58:32 +0000] [mydomain.com/sid#840f4b0][rid#864d898/initial] (2) [perdir /var/www/html/] rewrite 'portfolio/derp' -> 'index.php?portfolio=derp'
myip - - [11/Feb/2012:20:58:32 +0000] [mydomain.com/sid#840f4b0][rid#864d898/initial] (3) split uri=index.php?portfolio=derp -> uri=index.php, args=portfolio=derp
myip - - [11/Feb/2012:20:58:32 +0000] [mydomain.com/sid#840f4b0][rid#864d898/initial] (3) [perdir /var/www/html/] add per-dir prefix: index.php -> /var/www/html/index.php
myip - - [11/Feb/2012:20:58:32 +0000] [mydomain.com/sid#840f4b0][rid#864d898/initial] (2) [perdir /var/www/html/] strip document_root prefix: /var/www/html/index.php -> /index.php
myip - - [11/Feb/2012:20:58:32 +0000] [mydomain.com/sid#840f4b0][rid#864d898/initial] (1) [perdir /var/www/html/] internal redirect with /index.php [INTERNAL REDIRECT]
myip - - [11/Feb/2012:20:58:32 +0000] [mydomain.com/sid#840f4b0][rid#8656878/initial/redir#1] (3) [perdir /var/www/html/] strip per-dir prefix: /var/www/html/index.php -> index.php
myip - - [11/Feb/2012:20:58:32 +0000] [mydomain.com/sid#840f4b0][rid#8656878/initial/redir#1] (3) [perdir /var/www/html/] applying pattern '^portfolio/([\w-]+)$' to uri 'index.php'
myip - - [11/Feb/2012:20:58:32 +0000] [mydomain.com/sid#840f4b0][rid#8656878/initial/redir#1] (1) [perdir /var/www/html/] pass through /var/www/html/index.php
myip - - [11/Feb/2012:20:58:32 +0000] [mydomain.com/sid#840f4b0][rid#864d898/initial] (3) [perdir /var/www/html/] add path info postfix: /var/www/html/portfolio -> /var/www/html/portfolio/indexstyles.css
myip - - [11/Feb/2012:20:58:32 +0000] [mydomain.com/sid#840f4b0][rid#864d898/initial] (3) [perdir /var/www/html/] strip per-dir prefix: /var/www/html/portfolio/indexstyles.css -> portfolio/indexstyles.css
myip - - [11/Feb/2012:20:58:32 +0000] [mydomain.com/sid#840f4b0][rid#864d898/initial] (3) [perdir /var/www/html/] applying pattern '^portfolio/([\w-]+)$' to uri 'portfolio/indexstyles.css'
myip - - [11/Feb/2012:20:58:32 +0000] [mydomain.com/sid#840f4b0][rid#864d898/initial] (1) [perdir /var/www/html/] pass through /var/www/html/portfolio
myip - - [11/Feb/2012:20:58:32 +0000] [mydomain.com/sid#840f4b0][rid#86518a8/initial] (3) [perdir /var/www/html/] add path info postfix: /var/www/html/portfolio -> /var/www/html/portfolio/jquery-1.7.1.min.js
myip - - [11/Feb/2012:20:58:32 +0000] [mydomain.com/sid#840f4b0][rid#86518a8/initial] (3) [perdir /var/www/html/] strip per-dir prefix: /var/www/html/portfolio/jquery-1.7.1.min.js -> portfolio/jquery-1.7.1.min.js
myip - - [11/Feb/2012:20:58:32 +0000] [mydomain.com/sid#840f4b0][rid#86518a8/initial] (3) [perdir /var/www/html/] applying pattern '^portfolio/([\w-]+)$' to uri 'portfolio/jquery-1.7.1.min.js'

myip - - [11/Feb/2012:20:58:32 +0000] [mydomain.com/sid#840f4b0][rid#86518a8/initial] (1) [perdir /var/www/html/] pass through /var/www/html/portfolio
myip - - [11/Feb/2012:20:58:32 +0000] [mydomain.com/sid#840f4b0][rid#864d898/initial] (3) [perdir /var/www/html/] add path info postfix: /var/www/html/portfolio -> /var/www/html/portfolio/scripts/all.js
myip - - [11/Feb/2012:20:58:32 +0000] [mydomain.com/sid#840f4b0][rid#864d898/initial] (3) [perdir /var/www/html/] strip per-dir prefix: /var/www/html/portfolio/scripts/all.js -> portfolio/scripts/all.js
myip - - [11/Feb/2012:20:58:32 +0000] [mydomain.com/sid#840f4b0][rid#864d898/initial] (3) [perdir /var/www/html/] applying pattern '^portfolio/([\w-]+)$' to uri 'portfolio/scripts/all.js'
myip - - [11/Feb/2012:20:58:32 +0000] [mydomain.com/sid#840f4b0][rid#864d898/initial] (1) [perdir /var/www/html/] pass through /var/www/html/portfolio
myip - - [11/Feb/2012:20:58:32 +0000] [mydomain.com/sid#840f4b0][rid#864d898/initial] (3) [perdir /var/www/html/] add path info postfix: /var/www/html/portfolio -> /var/www/html/portfolio/scripts/jquery.history.js
myip - - [11/Feb/2012:20:58:32 +0000] [mydomain.com/sid#840f4b0][rid#864d898/initial] (3) [perdir /var/www/html/] strip per-dir prefix: /var/www/html/portfolio/scripts/jquery.history.js -> portfolio/scripts/jquery.history.js
myip - - [11/Feb/2012:20:58:32 +0000] [mydomain.com/sid#840f4b0][rid#864d898/initial] (3) [perdir /var/www/html/] applying pattern '^portfolio/([\w-]+)$' to uri 'portfolio/scripts/jquery.history.js'
myip - - [11/Feb/2012:20:58:32 +0000] [mydomain.com/sid#840f4b0][rid#864d898/initial] (1) [perdir /var/www/html/] pass through /var/www/html/portfolio
myip - - [11/Feb/2012:20:58:32 +0000] [mydomain.com/sid#840f4b0][rid#86588c0/initial] (3) [perdir /var/www/html/] add path info postfix: /var/www/html/portfolio -> /var/www/html/portfolio/img/projectimg/leoimg.png
myip - - [11/Feb/2012:20:58:32 +0000] [mydomain.com/sid#840f4b0][rid#86588c0/initial] (3) [perdir /var/www/html/] strip per-dir prefix: /var/www/html/portfolio/img/projectimg/leoimg.png -> portfolio/img/projectimg/leoimg.png
myip - - [11/Feb/2012:20:58:32 +0000] [mydomain.com/sid#840f4b0][rid#86588c0/initial] (3) [perdir /var/www/html/] applying pattern '^portfolio/([\w-]+)$' to uri 'portfolio/img/projectimg/leoimg.png'
myip - - [11/Feb/2012:20:58:32 +0000] [mydomain.com/sid#840f4b0][rid#86588c0/initial] (1) [perdir /var/www/html/] pass through /var/www/html/portfolio
myip - - [11/Feb/2012:20:58:32 +0000] [mydomain.com/sid#840f4b0][rid#864d898/initial] (3) [perdir /var/www/html/] add path info postfix: /var/www/html/portfolio -> /var/www/html/portfolio/img/projectimg/regformimg.png
myip - - [11/Feb/2012:20:58:32 +0000] [mydomain.com/sid#840f4b0][rid#864d898/initial] (3) [perdir /var/www/html/] strip per-dir prefix: /var/www/html/portfolio/img/projectimg/regformimg.png -> portfolio/img/projectimg/regformimg.png
myip - - [11/Feb/2012:20:58:32 +0000] [mydomain.com/sid#840f4b0][rid#864d898/initial] (3) [perdir /var/www/html/] applying pattern '^portfolio/([\w-]+)$' to uri 'portfolio/img/projectimg/regformimg.png'
myip - - [11/Feb/2012:20:58:32 +0000] [mydomain.com/sid#840f4b0][rid#864d898/initial] (1) [perdir /var/www/html/] pass through /var/www/html/portfolio
myip - - [11/Feb/2012:20:58:32 +0000] [mydomain.com/sid#840f4b0][rid#86588c0/initial] (3) [perdir /var/www/html/] add path info postfix: /var/www/html/portfolio -> /var/www/html/portfolio/img/projectimg/fileupimg.png
myip - - [11/Feb/2012:20:58:32 +0000] [mydomain.com/sid#840f4b0][rid#86588c0/initial] (3) [perdir /var/www/html/] strip per-dir prefix: /var/www/html/portfolio/img/projectimg/fileupimg.png -> portfolio/img/projectimg/fileupimg.png
myip - - [11/Feb/2012:20:58:32 +0000] [mydomain.com/sid#840f4b0][rid#86588c0/initial] (3) [perdir /var/www/html/] applying pattern '^portfolio/([\w-]+)$' to uri 'portfolio/img/projectimg/fileupimg.png'
myip - - [11/Feb/2012:20:58:32 +0000] [mydomain.com/sid#840f4b0][rid#86588c0/initial] (1) [perdir /var/www/html/] pass through /var/www/html/portfolio
myip - - [11/Feb/2012:20:58:32 +0000] [mydomain.com/sid#840f4b0][rid#86588c0/initial] (3) [perdir /var/www/html/] add path info postfix: /var/www/html/portfolio -> /var/www/html/portfolio/img/projectimg/carimg.png
myip - - [11/Feb/2012:20:58:32 +0000] [mydomain.com/sid#840f4b0][rid#86588c0/initial] (3) [perdir /var/www/html/] strip per-dir prefix: /var/www/html/portfolio/img/projectimg/carimg.png -> portfolio/img/projectimg/carimg.png
myip - - [11/Feb/2012:20:58:32 +0000] [mydomain.com/sid#840f4b0][rid#86588c0/initial] (3) [perdir /var/www/html/] applying pattern '^portfolio/([\w-]+)$' to uri 'portfolio/img/projectimg/carimg.png'
myip - - [11/Feb/2012:20:58:32 +0000] [mydomain.com/sid#840f4b0][rid#86588c0/initial] (1) [perdir /var/www/html/] pass through /var/www/html/portfolio
myip - - [11/Feb/2012:20:58:32 +0000] [mydomain.com/sid#840f4b0][rid#864d898/initial] (3) [perdir /var/www/html/] add path info postfix: /var/www/html/portfolio -> /var/www/html/portfolio/img/chromeicon.png
myip - - [11/Feb/2012:20:58:32 +0000] [mydomain.com/sid#840f4b0][rid#864d898/initial] (3) [perdir /var/www/html/] strip per-dir prefix: /var/www/html/portfolio/img/chromeicon.png -> portfolio/img/chromeicon.png
myip - - [11/Feb/2012:20:58:32 +0000] [mydomain.com/sid#840f4b0][rid#864d898/initial] (3) [perdir /var/www/html/] applying pattern '^portfolio/([\w-]+)$' to uri 'portfolio/img/chromeicon.png'
myip - - [11/Feb/2012:20:58:32 +0000] [mydomain.com/sid#840f4b0][rid#864d898/initial] (1) [perdir /var/www/html/] pass through /var/www/html/portfolio
share|improve this question

1 Answer 1

up vote 3 down vote accepted

Remove the / from the start of the rule; you've got this in a per-directory context (either an .htaccess file or <Directory> block) so there's no leading slash.

RewriteRule ^portfolio/([\w-]+)$ index.php?portfolio=$1

You may also have some issues with your other rules once you fix this - give that a try but if it's still broken, can you provide the rest of your config?

share|improve this answer
    
Removing the leading slash directs to portfolio.php ... I'll pop the whole ht access up . –  Frank Astin Feb 11 '12 at 20:40
    
ok , I stripped down the .htaccess to just this RewriteEngine On Options +FollowSymlinks RewriteCond %{SCRIPT_FILENAME} !-d RewriteCond %{SCRIPT_FILENAME} !-f RewriteRule ^/portfolio/([\w-]+)$ index.php?portfolio=$1 and with the leading slash I get a 404 without 'portfolio.php' –  Frank Astin Feb 11 '12 at 20:45
    
The leading slash will never ever work in a per-directory context - still needs to be removed. –  Shane Madden Feb 11 '12 at 20:50
    
updated answer with new log –  Frank Astin Feb 11 '12 at 21:02
    
@FrankAstin It's serving index.php: pass through /var/www/html/index.php. The browser's even sending a request for indexstyles.css; there's nary a mention of a file named portfolio.php in that log. Are you certain it's being used? –  Shane Madden Feb 11 '12 at 22:34

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.