I used to work on localhost with this .htaccess:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [QSA,L]
now when I uploaded it online it's giving me 403 Forbidden, is there any other things to change in that file.
Related
How do I create dynamic .htaccess file that recognizes the server path. It needs to work on localhost folder which path is:
/Library/WebServer/Documents/myscaryproject/.htaccess
and on hosted server path which is:
/domains/mydomain/.htaccess
This is my .htaccess currently:
ErrorDocument 404 /myscaryproject/404.php
RewriteEngine on
# removing index.php from url
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)$ /myscaryproject/index.php?event=$1 [L]
# removing index.php and replacing it with event and page parameter
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([^/]+)$ /myscaryproject/index.php?event=$1&p=$2 [L]
RewriteRule ^login/?$ login.php [NC]
This all doesn't work if I push it to the server, because pathing isn't correct.
In my .htaccess file, I have the settings for rewriting urls such as http://www.myownwebsite.com/about.php to http://www.myownwebsite.com/about/.
And I also have the settings for custom error 403 and 404 pages.
The issue I'm encountering is that, when I'm testing accessing a folder directly, for example, http://www.myownwebsite.com/css/, instead of seeing the custom 403 page, I'm seeing the custom 404 page. I guess that's because the settings of url rewriting is overwriting the setting of custom 403 page.
Here is the related code in my .htaccess file:
ErrorDocument 403 /403.php
ErrorDocument 404 /404.php
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/$ $1.php
RewriteRule ^([^/]+)/([^/]+)/$ /$1/$2.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule (.*)$ /$1/ [R=301,L]
What am I doing wrong?
Before adding .php to your URIs make sure corresponding .php file exists.
Better to keep redirect rule before other rules.
Have it like this:
Options -MultiViews -Indexes
ErrorDocument 403 /403.php
ErrorDocument 404 /404.php
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule (.*)$ /$1/ [R=301,L]
RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^([^/]+)/$ $1.php [L]
RewriteCond %{DOCUMENT_ROOT}/$1/$2.php -f
RewriteRule ^([^/]+)/([^/]+)/$ /$1/$2.php [L]
I get that error when i upload my website to host and try to go on blabla.com/admin/ but on my xampp everything is working fine...any help? This is my .htaccess
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
I was wondering why my htaccess would not allow for multiple rules? Here is the code:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ $1.php [QSA,L]
Basically I wanted to add a 404 rule. Here is the code:
ErrorDocument 404 http://xxxxxx/404.php
Well basically I can not add all of the together in one htaccess file. Here is the code:
ErrorDocument 404 http://xxxxxx/404.php
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ $1.php [QSA,L]
That code above will not work all together. Why is that?
It's not working because basically you are doing two times the same thing in the .htaccess:
ErrorDocument 404 http://xxxxxx/404.php
The ErrorDocument redirects to 404 in case the requested page is not found. The two RewriteConds RewriteCond %{REQUEST_FILENAME} !-f and RewriteCond %{REQUEST_FILENAME} !-d plus the RewriteRule will do exactly the same, they will redirect if the request file was not found - in your case they are redirecting to index.php.
So you can try either of the two following:
RewriteEngine on
ErrorDocument 404 /404.php
or
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ 404.php [QSA,L]
Currently the URL is being treated as a string, to let it know it's a path you should add a slash at the beginning
try this and see if it works
ErrorDocument 404 /404.php
Need help with .htaccess
I have website on my localhost with this .htaccess
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ website/index.php/$1 [L]
Now i want to move the site to subdomain.domain.com
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ http://subdomain.domain.com/index.php/$1 [L]
I chaged the url but this doesn'n work maybe because this is subdomain i don't know
hosting details:
# Subdomain Name Path [?]
1 subdomain.domain.com /home/www/subdomain.domain.com
my urls are like this
http://website/index.php/contact
with this htaccess i can use
http://website/contact
When i moved the site to the subdomain i can use http://subdomain.website/index.php/contact but when try http://subdomain.website/contact gives me error
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Try with this one, it should work for all domains localhost as well as server.
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
Make sure "rewrite_engine = on" on server.