Error on rewrite rule inside subdirectory - .htaccess

When my website was inside the root directory of my hosting, everything works find. However, I had to move my website files to a subdirectory.
Old:
/www/*
Current:
/www/websites/example
Now, I can visit the homepage of my website, but I get error when I visit other pages of my site.
example.com/1234/title_of_url -> example.com/index.php?qa-rewrite=1234/title_of_url
But when I visit that sample page, i get the following error.
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator and inform them of the time the error occurred, and the actions you performed just before this error.
More information about this error may be available in the server error log.
Here is my .htaccess file:
RewriteEngine On
RewriteCond %{REQUEST_URI} ^(.*)//(.*)$
RewriteRule . %1/%2 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ index.php?qa-rewrite=$0&%{QUERY_STRING} [L]
Note: I have moved the file to my /www/ dir and it works fine. So I think I am missing to put websites/example somewhere in my .htaccess

Use this rule in site root .htaccess:
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/websites/ [NC]
RewriteRule .* websites/example/$0 [L]
Then use this code in websites/example/.htaccess:
RewriteEngine On
RewriteBase /websites/example/
RewriteCond %{REQUEST_URI} ^(.*)//(.*)$
RewriteRule . %1/%2 [R=301,L,NE]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(?!index\.php$).*$ index.php?qa-rewrite=$0 [NC,L,QSA]

Related

yii2 404 page not found when trying remove /web from url with .htaccess

Im'm trying to remove this /web from the url in Yii2 basic temeplate with .htaccess files. And i found a solution for it already but a problem has occured!
So the solution i have found earlier is:
1)Put in root/web folder .htaccess:
RewriteEngine On RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php
2)Put in root folder .htaccess:
Options +FollowSymLinks
IndexIgnore */*
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/(web)
RewriteRule ^assets/(.*)$ /web/assets/$1 [L]
RewriteRule ^css/(.*)$ web/css/$1 [L]
RewriteRule ^js/(.*)$ web/js/$1 [L]
RewriteRule ^images/(.*)$ web/images/$1 [L]
RewriteRule (.*) /web/$1
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /web/index.php
3)Add in config/web.php in request part 'baseUrl'=> ''
The problem occured after steps 2 and 3 are made. Browser tells:
Not Found
The requested URL /web/index.php was not found on this server.
Apache/2.4.23 (Win64) PHP/5.6.25 Server at localhost Port 80
All this happens when I'm doing it on my local server wich is WAMP. I tried to place this project on free hosting and evrything seem to work there. So how can I fix this problem on my local server? Why does it give me the 404 error?
Try in the root .htaccess replace
RewriteRule (.*) /web/$1
on
RewriteRule ^(.*)$ /web/$1 [L,PT]

Codeigniter 3 subdomain not working for other pages

I have created sub-domain like this in Codeigniter 3
www.test.example.com
I have used this .htaccess and it's working only home page.
www.test.exapmle.com for other pages like www.test.exapmle.com/page1 or www.test.exapmle.com/page2
.htaccess I used:
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /public_html/index.php/$1 [L,QSA]
I am getting this error:
the server encountered an internal error or misconfiguration and was
unable to complete your request.
In .htaccess file just insert the following code
RewriteEngine on
RewriteCond %{HTTP_HOST} ^([^\.]+)\.example\.com$ [NC]
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 [L]

Forbidden: Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request

Hi i have this folder on my server and it is clients/nannyshareaustralia and im using a codeigniter framework i already set up the config.php in the base url too. And im adding also for the htaccess file
RewriteEngine On
RewriteCond %{REQUEST_URI} ^system.*
RewriteCond $1 ^(index\.php|robots\.txt|favicon\.ico|images|js|assets|css)
RewriteRule ^(.*)$ /clients/nannyshareaustralia/index.php?/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /clients/nannyshareaustralia/index.php?/$1 [L]
and when i run it to the browser this is what it goes
Forbidden
You don't have permission to access /clients/nannyshareaustralia on this server.
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
can someone help me figured this out? Any help is muchly appreciated
Please try this Following code write in your .htaccess file
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule>
RewriteEngine On
RewriteBase /clients/nannyshareaustralia
RewriteCond %{REQUEST_URI} ^system.*
RewriteCond $1 ^(index\.php|robots\.txt|favicon\.ico|images|js|assets|css)
....
Added a RewriteBase rule to your .htaccess granting that mod_rewrite is enabled on your server.
note
If you access the directory like www.domain.com/clients/nannyshareaustralia you must add a RewriteBase to the .htaccess
But if a url/domain is pointed at the folder clients/nannyshareaustralia there is no need for the RewriteBase.

codeigniter htaccess with multiple applications

I am using codeigniter. I have front end application and backend application like
/system/
/application/
/front/
/admin/
index.php
admin.php
.htaccess
I want my url like http://example.com/news/article1 (for site)
http://example.com/news/admin (for admin)
In .htaccess I have written
RewriteEngine On
# If the user types just "admin".
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/admin$ admin\.php [L,QSA]
# If the user enter in any admin section, like "admin/section".
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/admin\/(.*)$ admin\.php/$1 [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
the front end is working fine but when I enter mydomain.com/admin it is throwing 404 not found error. Please help me.
Thanks and regards
I'm not that good with .htaccess, but from the CI website, you can use this for your .htaccess rule
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
and then use routes to rewrite your urls. Much easier than trying to do it in .htaccess files

htaccess for subdomain

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.

Resources