sensation
sensation

Reputation: 437

Rewrite rule in subdirectory

Rewrite rule does not work on remote host in subdirectory.

While in production phase, I had this directory http://localhost/prj/. I used RewriteRule to "hide" and "load" PHP files without extension. This is the .htaccess I've used:
Options +FollowSymLinks RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME}\.php -f RewriteRule ^(.*)$ $1.php

So, that worked fine, I've developed the project and I wanted to upload it to my VPS for remote use and such. The thing is, the project is still in beta, and I don't keep it in root directory ATM but at subdirectory /beta/, so now, this my URL right now is like this: http://example.com/beta/.

Yet when I tried to access that URL, the index.php is automatically loaded, but when I access for example file play.php as http://example.com/beta/play it doesn't work but it worked while the project was in production.

This is what I have tried:

Example:

Options All -Indexes -MultiViews
RewriteEngine on
RewriteBase /beta/
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME}\.php -f 
RewriteRule ^(.*)$ $1.php [L,QSA]  



Options All -Indexes -MultiViews
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME}\.php -f 
RewriteRule ^/beta/(.*)$ $1.php [L,QSA]

Returned error is 404 Not found.
Edit: I'm I supposed to have too inside apache2.conf?

Upvotes: 2

Views: 2388

Answers (1)

anubhava
anubhava

Reputation: 786091

Try this in /beta/.htaccess:

Options All -Indexes -MultiViews
RewriteEngine on
RewriteBase /beta/

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

Upvotes: 1

Related Questions