idris
idris

Reputation: 1049

Can't rewrite URL in a directory

So here's my regex

Options -MultiViews
DirectoryIndex index.php
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^article/([0-9]+)$ article.php?id=$1 [L,QSA,NC]
RewriteRule ^site/(.*)$ site.php?id=$1 [L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1\.php -f [NC]
RewriteRule ^(.+?)/?$ /$1.php [L]

And this is what I want my URL to look like:

http://localhost/developer/site/google.com

So I'd do

RewriteRule ^site/(.*)$ site.php?id=$1 [L]

But when I go to the URL all I get is

Not Found

The requested URL /developer/site/google.com was not found on this server.

Even though I have an site.php in my developer folder. Any ideas?

Upvotes: 1

Views: 32

Answers (1)

Justin Iurman
Justin Iurman

Reputation: 19016

You have to use a correct path for your rewrite (RewriteBase) assuming your htaccess is in developer folder.

Also, please don't forget that RewriteCond are for next RewriteRule only.

Options -MultiViews

RewriteEngine On
RewriteBase /developer/

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^article/([0-9]+)$ article.php?id=$1 [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^site/([^/]+)$ site.php?id=$1 [L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/developer/$1\.php -f [NC]
RewriteRule ^(.+?)/?$ $1.php [L]

Upvotes: 1

Related Questions