Yii2 advanced theme backend access - .htaccess

i'm having a problem accessing the backend section of my advanced theme. Basically i can't access after make changes in .htaccess for frontend section.
In root folder the .htaccess is:
RewriteOptions inherit
Options -Indexes
RewriteEngine on
<IfModule mod_rewrite.c>
RewriteCond %{REQUEST_URI} !^/frontend/web/(assets|css|stylesheets|images|js)/
RewriteCond %{REQUEST_URI} !admin
RewriteRule .* frontend/web/index.php [L]
</IfModule>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php

When you enable the pretty url component in either frontend / backend application of the yii2-advenced template, make sure you create a .htaccess file under the web folder of the respective application with the following content
# use mod_rewrite for pretty URL support
RewriteEngine on
# if a directory or a file exists, use the request directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# otherwise forward the request to index.php
RewriteRule . index.php
NOTE: rewrite_module should be enabled in apache for this to work.

Related

.htaccess Redirect url to folder

I have a blog folder in my servers /home/app/sites directory, and I have my laravel app in /home/app/public_html/laravel and my domain www.laravelapp.com is pointing to the project.
I want to point the url www.laravelapp.com/blog to my blog folder in /home/app/sites/blog.
How can I do that?
Here is my .htaccess file:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect blog folder (Not working)
RewriteCond %{HTTP_HOST} ^www.laravelapp.com/blog$ [NC]
RewriteRule ^(.*)$ /home/app/sites/blog [L,R=301]
</IfModule>
../ goes one folder down
So it should be ../../sites/blog
There may be restrictions with htaccess. If this not already work share your .htaccess file. You cant go behind your base url, the following question explains it very well.
Having links relative to root?

.htaccess isn't loading static html pages in additional domain

I'm having problems to browse normal html pages inside my additional domain, example-domain.com
here's my file structure
public_html
-css
-img
-js
example-domain.com <- get server error
- index.html
-products.html
- contact.html
-system
.htaccess
index.php
I use codeigniter framework in the main site, and simple html within the additional domain
example-domain.com , when i put the url to browse example-domain.com, i get a 500 internal server error I think it's due to my .htaccess file i 'm using for the main domain. How can I modify it to load simple .html files inside my additional domain as well.
my .htaccess
RewriteEngine on
RewriteCond $1 !^(index\.php|img|css|js|uploads|robots\.txt|sitemap\.xml)
RewriteRule ^(.*)$ index.php/$1 [L]
Currently, what I see, you are trying to do the redirect, if the requested URL is not a file and not a directory. It can be done, using these directives:
RewriteEngine On
Options -MultiViews
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/$1 [L]
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

Restrict directory for Friendly URLs .htaccess

I want the site to be url friendly match, so that the directory / adm (which in my case is the administrative panel) has not url friendlies
my .htaccess
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
</IfModule>
# For all files not found in the file system, reroute the request to the
# "index.php" front controller, keeping the query string intact
<IfModule mod_rewrite.c>
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [L]
</IfModule>
I just want to do this I'm learning this rule means in layman commands. htaccess
All your scripts will be redirected to index.php based on below
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [L]
In addition you can specify the folder name, filename which should not follow the above rule. This can be done by adding another rewrite condition statement in your htaccess file.
RewriteCond %{REQUEST_FILENAME} !(img|anyother folders that you want to ignore|anyother folders that you want to ignore|...)
'|' is used to separate each folder name that you want to ignore
So your .htaccess file will have following
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
</IfModule>
# For all files not found in the file system, reroute the request to the
# "index.php" front controller, keeping the query string intact
<IfModule mod_rewrite.c>
RewriteCond %{REQUEST_FILENAME} !(adm|anyother folders that you want to ignore|anyother folders that you want to ignore|...)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [L]
</IfModule>

How to redirect using .htaccess in apache?

I am trying to create a user management system where users can register another users using their pre-created user links such as http www .abc .co. uk/access/register.php?id=username [sorry not allowing to put more links]
but I want the long link to be like this:
http://www.abc.co.uk/username
and when users type the short url it will re-direct to http://www.abc.co.uk/access/register.php?id=username
Below are the codes in my .htaccess file at the moment as I am also running a wordpress in the same domain.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(\w+)$ ./access/register.php?id=$1 [L,QSA]
Can the .htaccess additional codes that I have added for the username redirect be used along with other wordpress redirect in the same .htaccess file?
When I type the short url in the browser it takes me to a "page not found" page.
I have tried several ways and the above codes does not work. Could anyone please help me? Thanks
Jay
What you want is not possible. How could apache differentiate between wordpress pages and usernames?
www.abc.co.uk/contact could be your contact site or the user “contact”. You need to put your referrer urls in a subfolder, eg. register (so you get abc.co.uk/register/username:
RewriteEngine On
RewriteBase /
# Register
RewriteRule ^/register/(.+)$ ./access/register.php?id=$1 [L,QSA]
# Wordpress
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

How to Remove index.php from URL in PHP

I want to remove index.php from url but so far i couldn't succeed it. I'm using Wamp server on my local and Apache on remote server..
In local root directory, my project files are located in a subfolder like
www/project/index.php
I can access web pages like
localhost/project/index.php/home
localhost/project/index.php/messages/?mId=3
I just want to access it like
localhost/project/home
localhost/project/messages/?mId=3
I already tried some .htaccess rewrite rule but couldnt make it.
Here's how you need to organize:
<ifModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/$1 [NC,QSA,L]
</ifModule>
And then you will have everything as you need.
You will want to use url rewriting with a .htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
</IfModule>
Put a .htaccess with this content in each subfolder.

Resources