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:
To use RewriteBase to /beta/
RewriteBase /beta/
To use different options
Options All -Indexes -MultiViews
To use directory before actual RewriteRule
RewriteRule ^/beta/(.*)$ $1.php
To use operatives [L, QSA]
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?
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]
Related
This is my currently my .htaccess file
Options -MultiViews
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php [NC]
RewriteRule ^(.*)/edit/(\d+)?$ $1/edit.php?tag=$2 [NC]
As you can see it's set to hide the .php extension, but this then seems to break the edit rule. If I comment out
RewriteRule ^(.*)$ $1.php [NC]
The edit rule works fine, but I need both and cannot seem to get it to work, anyone see what the problem is and how to sort it.
[Edit]
I have a link like this and when all rules are active this is what doesn't work.
http://www.domainname.com/researcher/lists/edit/
and I get an 500 Internal Server Error.
Try rules as in your site root .htaccess:
Options -MultiViews
RewriteEngine on
RewriteRule ^(.+)/edit(?:/(\d+))?/?$ $1/edit.php?tag=$2 [NC,L,QSA]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+?)/?$ $1.php [L]
I'm trying to build a shopping cart using PHP & MySQL. Right now I'm in the process of creating product-detail pages. So this is how I set up my htaccess (located in the root folder):
Options +FollowSymLinks
Options -Indexes
DirectoryIndex index.php
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|images|css|js|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^\.]+)$ $1.php [NC,L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 /index.php
</IfModule>
My problem is I can only access a certain page if index.php is included. For example, http://localhost/thegamingplace/products/details/1 displays a "Not Found" error, but http://localhost/thegamingplace/index.php/products/details/1 works.
Can someone take a look at my htaccess and tell me what I'm doing wrong?
Try this:
RewriteCond %{REQUEST_URI} !^(index\.php|resources|images|css|js|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^\.]+)$ index.php/$1 [NC,L]
It works when tested at http://htaccess.mwl.be/
If it doesn't work make sure you have mod_rewrite installed and enabled.
Hi I have the following redirection for a friendly URL site
Options +FollowSymLinks -Multiviews
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
rewritecond %{SCRIPT_FILENAME} !-d
rewritecond %{SCRIPT_FILENAME} !-f
rewriterule ^(.*)$ $1.php [L]
rewriterule ^noticia/([a-zA-Z0-9_-]+)$ noticia.php?title=$1 [L]
</IfModule>
If i go to www.mysite.com/noticias or any other URL like that everything goes ok
But if i try to go to www.mysite.com/noticia/this-is-a-parameter
When I access a link I do it like <a href="noticia/this-is-a-parameter">
I get Internal Server Error message and white screen
In localhost it was working perfectly, but can't find a solution in the server.
Any help would be appreciated
Check for presence of .php file before adding php extension and reorder your rules:
Options +FollowSymLinks -Multiviews
RewriteEngine on
RewriteBase /
RewriteRule ^noticia/([\w-]+)/?$ noticia.php?title=$1 [L,QSA,NC]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+?)/?$ $1.php [L]
I have two websites, xyz.com and testsite.com (just for example). I've linked my domain xyz.com to testsite.com/content. My testsite.com/content features a .htaccess which features the following code meant to remove the .php extension from the URL:
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
It works perfectly fine on the source website; however, it shoots off a 404 error in the xyz.com and references /content/content/login instead of /content/login in the testsite.com. How do I fix this?
Add RewriteBase / to the code so like this
Options -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
If it doesn't work like this, try adding the rewritebase under the options or at the top of the htaccess.
I am trying to prevent direct access to all php files on my site except index.php using htaccess. I've got following code so far, however it still does not prevent form accessing php files directly.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php)
RewriteRule ^(.*)$ index.php?page=$1 [L]
</IfModule>
My Solution:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond $1 !^(index\.php|.*\.css|.*\.js|.*\.png|.*\.gif|.*\.jpg)
RewriteRule ^(.*)$ index.php?page=$1 [L]
</IfModule>
That's because of these lines:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
Where you are explicitly telling the rewrite module to NOT run the following rules if the requested resource is a file or directory
However, I agree it's best to move them out of the web root entirely.