I'm new to Yii2,
here is the website almousa.net
the issue here that I can not go to the backend, I always get The requested page does not exist and the page title Not Found (#404)
I tried everything from changing the .htaccess to changing the url
how can I solve that?
I noticed that there are no index.php in the website base folder and as if all the requests are going to the front end
Even I have installed a fresh copy of Yii2 advanced and following standard steps I got everything OK. But the same problem like you mentioned here that the backend was not working.For this I added an additional .htaccess file inside backend folder(/backend) with the following code:
Options -Indexes
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_URI} !^public
RewriteRule ^(.*)$ web/$1 [L]
</IfModule>
# Deny accessing below extensions
<Files ~ "(.json|.lock|.git)">
Order allow,deny
Deny from all
</Files>
# Deny accessing dot files
RewriteRule (^\.|/\.) - [F]
Please do follow and I hope it helps.Your config settings must be correct in addition to 1 more .htaccess inside backend/web folder with the following code:
RewriteEngine on
# If a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Otherwise forward it to index.php
RewriteRule . index.php
Related
I was on live chat with my domain support and they managed to delete the default htaccess file, now every url entered goes to my main index, what can I do to fix this?
Example:
domain: example.com
If I have a folder under example.com/folder
and go to it, the index for example.com shows instead of for that folder and if I put the path directly it stays in the browser but it shows the index for example.com always.
What can I write in my htaccess to fix this to how it used to be and keep mod rewrite enabled?
Edit: also, every time I've asked them to fix it or reset it to default they claim that it's a web development issue and not theirs. All they do is tell me to contact my developer.
hopefully, it works
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
#This last condition enables access to the images and css folders, and the robots.txt file
RewriteCond $1 !^(index\.php|public|images|robots\.txt|css)
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
I am currently trying to using .htaccess to do the following:
When b/ is found in the url, it redirects to browse.html. My .htaccess file looks like:
RewriteEngine On # Turn on the rewriting engine
RewriteRule ^b/(.*)$ browse.html [NC,L]
I am using Apache version 2.2.31 and here is what my directory looks like:
Root
Root/browse.html
Root/[css]
Root/css/browse.css
Root/[js]
Root/js/browse.js
When I do this, it brings me to browse.html but nothing loads correctly. Every file in the css and js directories become browse.html. Is there something extra I need to add to this?
Here is what the dev tools directory looks like with the .htacess
localhost
b/?page=1 (browse.html file. Name comes from query string)
b/[css]
b/css/browse.css (blank file)
b/[js]
b/js/browse.js (browse.html instead of browse.js)
I have tried putting RewriteBase / in between but that does nothing to the problem.
Your rewrite rule is fine. Problem is happening due to your use of relatives paths for css/js/images. While resolving relative paths browser appends it to current page's path.
You can add this rule above your existing rule::
RewriteEngine On
# fix css/js paths
RewriteRule ^b/.*((?:js|css)/.+)$ /$1 [NC,R=301,L]
RewriteRule ^b/(.*)$ browse.html [NC,L]
Make sure to ignore requests if files/folders exists:
RewriteEngine On # Turn on the rewriting engine
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^b/(.*)$ browse.html [NC,L]
I installed mediawiki on my website. I had a problem where my wiki pages started with www.mywebsite/mywiki/index.php/mywikipage. I wanted to get rid off this "index.php" so I made short url to my wiki with this website: http://shorturls.redwerks.org/. From here I got one code to .htaccess:
DirectoryIndex RewriteEngine On
RewriteRule ^/?wiki(/.*)?$ %{DOCUMENT_ROOT}/w/index.php [L]
RewriteRule ^/?$ %{DOCUMENT_ROOT}/w/index.php [L]
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-d
RewriteRule ^/?w/images/thumb/[0-9a-f]/[0-9a-f][0-9a-f]/([^/]+)/([0-9]+)px-.*$ %{DOCUMENT_ROOT}/w/thumb.php?f=$1&width=$2 [L,QSA,B]
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-d
RewriteRule ^/?w/images/thumb/archive/[0-9a-f]/[0-9a-f][0-9a-f]/([^/]+)/([0-9]+)px-.*$ %{DOCUMENT_ROOT}/w/thumb.php?f=$1&width=$2&archived=1 [L,QSA,B]
And another what went to LocalSettings.php in my wiki folder:
## The URL base path to the directory containing the wiki;
## defaults for all runtime URL paths are based off of this.
## For more information on customizing the URLs please see:
## http://www.mediawiki.org/wiki/Manual:Short_URL
$wgScriptPath = "/w";
$wgScriptExtension = ".php";
$wgArticlePath = "/wiki/$1";
$wgUsePathInfo = true;
## To enable image uploads, make sure the 'images' directory
## is writable, then set this to true:
$wgEnableUploads = true;
$wgGenerateThumbnailOnParse = false;
After this I had no more problem with the URL of my wiki pages. But my website front page goes to wiki now. I want it back to index.html. I tried to put this code into my .htaccess file but still doesn't work.
Options +FollowSymlinks
RewriteEngine on
RewriteBase /
DirectoryIndex index.html
Any help would be great! Thank you!
The rule is currently rewriting homepage to /w/index.php
Change this :
RewriteRule ^/?$ %{DOCUMENT_ROOT}/w/index.php [L]
to
RewriteRule ^/?$ %{DOCUMENT_ROOT}/index.html [L]
so that a request for hompage can internally redirect to /index.html
Today I tried to write a .htaccess file for first time in order to remove .html extension from url bar along with some other things that I wanted to do. Since I was unfamiliar with all this I read several articles before coding.
I ended up with the following code. I also removed .html from all links. The problem is that when visiting my domain I get the following error.
//The resource you are looking for has been removed,
//had its name changed, or is temporarily unavailable.
Is my code correct?
UPDATED .htaccess
//Rewrite to www
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
//Remove .html UNTIL NOW THIS IS THE ONLY PART
//OF THE CODE THAT ACTUALLY WORKS.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.html [NC,L]
//Caching schema
<FilesMatch "\.(jpg|png)$">
Header set Cache-Control "private, max-age=160704000"
</FilesMatch>
//Prevent viewing of .htaccess file
<Files .htaccess>
order allow,deny
deny from all
</Files>
In a separate .htaccess
//Prevent directory listings
Options All -Indexes
MAIN ERRORS
If I click on link like:
Home
Then I get the same error.
Thank you all in advance.
This is native in Apache without using mod_rewrite by using MultiViews option.
Documentation states:
The effect of MultiViews is as follows: if the server receives a request for /some/dir/foo, if /some/dir has MultiViews enabled, and /some/dir/foo does not exist, then the server reads the directory looking for files named foo.*, and effectively fakes up a type map which names all those files, assigning them the same media types and content-encodings it would have if the client had asked for one of them by name. It then chooses the best match to the client's requirements.
I finally managed to resolve a part of the problem. For starters I changed my server from windows to linux.
Then to remove html extension I used this code in .htaccess (the other codes didn't work well, giving me an error message)
//Remove .html
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.html [NC,L]
I also removed any .html instances from all links.
Now it works like a charm.
I have ONE directory for my entire domain that I want to force https, which is "/docs". In the /docs folder, I have the following htaccess file:
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
This is forcing https to everything in the /docs directory, which is what I want it to do. The problem I am having is trying to force REMOVE https back to http for all other areas of my site. In the root folder of the site (which is running wordpress), I have the following htaccess file:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
RewriteCond %{HTTPS} on
RewriteCond %{REQUEST_URI} !^/docs/?.*$
RewriteRule ^(.*)$ http://www.mydomain.com/$1 [R=301,L]
Unfortunately, this is not working. I can still access other areas of my site over https.
What do I need to change to get this to work correctly?
Since the accepted answer doesn't actually answer the question, I figured I'd post my solution to this. Add this to your .htaccess file to force HTTP instead of HTTPS:
# BEGIN Force HTTP
RewriteEngine On
RewriteCond %{SERVER_PORT} 443
RewriteRule ^(.*)$ http://yourdomain.com/$1 [R=301,L]
# END Force HTTP
Try the Force non-SSL plugin for wordpress.
The "WordPress Force HTTP" plugin was the only thing that worked for me. It changes https to http for not just the front page like most of the answers out there, but also changes https to http for all sub-directories in your website.
https://en-au.wordpress.org/plugins/wp-force-http/
Why do you need to revert back to http? If you have the proper SSL certificates you might as well keep your access secure. Unless you are concerned about the load on your system.
I know this is not answering the question, but I want to emphasize that the question is asking on how to do a bad practice, which shouldn't be done in the first place.