I have a standard Larvael folder structure, and I want to have a Wordpress blog in /blog folder.
I am on a shared hosing, so I am using this htaccess at root of my domain to rewrite all requests to /public:
RewriteCond %{REQUEST_URI} !^public
RewriteRule ^(.*)$ public/$1 [L]
Then I thought I'd put blog in the root and just not do the rewriting if the route starts with blog:
RewriteCond %{REQUEST_URI} !^public
RewriteCond %{REQUEST_URI} !^blog
RewriteRule ^(.*)$ public/$1 [L]
But that didn't work.
How can I achieve this?
Thanks,
Petar
And with that:
RewriteCond %{REQUEST_URI} !^/public
RewriteCond %{REQUEST_URI} !^/blog
RewriteRule ^(.*)$ public/$1 [L]
Because URI begin with /
Related
I am editing a site that is made using some framework on PHP doesn't show which.
All the public files like CSS,JS are inside a Public directory. I want to upload a separate site within the domain like www.domain.com/newsite i have created the folder new site but i am not able to access it it goes to 404 page not found.
the Htacess of the root is as below
RewriteEngine on
RewriteRule ^(?!sitemap\.xml$).(.*)\.xml$ [R=404,L]
RewriteRule ^(?!robots\.txt$).(.*)\.txt$ [R=404,L]
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteRule ^$ public/ [L]
RewriteRule (.*) public/$1 [L]
<ifModule mod_headers.c>
Header set Access-Control-Allow-Origin: *
</ifModule>
I created anther folder inside public directory newsite still now able to open it.
Htacess inside public directory is
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
Any suggestions how can i access the folder directly
You only need to tell the root htaccess not to rewrite to public directory when your new folder is involved in the request. Currently, you have this part of code
RewriteRule ^$ public/ [L]
RewriteRule (.*) public/$1 [L]
which means: rewrite root page / to public folder (first rule) and rewrite everything to public folder as well (second rule). Note by the way that your first rule is then useless.
Anyway, you need to add a condition to reach your goal
RewriteCond %{REQUEST_URI} !^/newsite
RewriteRule ^(.*)$ public/$1 [L]
which means: rewrite everything except newsite folder to public folder.
At the end, your root htaccess should look like this
RewriteEngine on
RewriteBase /
RewriteRule ^(?!sitemap\.xml$).(.*)\.xml$ [R=404,L]
RewriteRule ^(?!robots\.txt$).(.*)\.txt$ [R=404,L]
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteCond %{REQUEST_URI} !^/newsite
RewriteRule ^(.*)$ public/$1 [L]
<ifModule mod_headers.c>
Header set Access-Control-Allow-Origin: *
</ifModule>
Note the presence of RewriteBase which is always a good habit, especially when dealing with virtual directories created by some rules. Note also that your two xml rules could be rewritten in a more clever/cleaner way
Try to add
RewriteBase /newsite/
Write this line under "RewriteEngine On"
Try to use below rules,
RewriteEngine on
RewriteRule ^(?!sitemap\.xml$).(.*)\.xml$ [R=404,L]
RewriteRule ^(?!robots\.txt$).(.*)\.txt$ [R=404,L]
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
#Adding exception for newsite if not new site do rewrite to public/
RewriteCond %{REQUEST_URI} ^!newsite
RewriteRule ^$ public/ [L]
RewriteRule (.*) public/$1 [L]
You are getting not found error because you are currently internally rewriting everything to public directory please try the new rules if you haven't.
How should my .htaccess code look like if I move my front controller? More specific, I had front controller in the following directory: root/public/index.php and my .htaccess looked like so:
RewriteEngine on
RewriteBase /
ReWriteCond %{REQUEST_URI} !public/
ReWriteRule ^(.*)$ public/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php?/$0 [PT,L]
Now when I move front controller to: root/en/index.php obviously my .htaccess becomes obosolete. Also I think I must change the path in my front controller? But lets fix the .htaccess first to work with the new structure.
Should be just a matter of rewriting:
ReWriteCond %{REQUEST_URI} !public/
ReWriteRule ^(.*)$ public/$1 [L]
To:
ReWriteCond %{REQUEST_URI} !en/
ReWriteRule ^(.*)$ en/$1 [L]
I have a domain, let's say somedomain.com. I have an admin page somedomain.com/admin. The pages were coded in plain PHP. I recently re-wrote somedomain.com in CodeIgniter. But I do not want to touch somedomain.com/admin for now.
How do I make this work? When I go to somedomain.com/admin, it is looking an admin controller, which of course does not exist. I have an index.php file in admin folder, I cannot figure out a way to access the index file.
Thank you.
You should post .htaccess for us to se. But anyway. You should exclude "admin" to be directed to index.php
something like this
RewriteEngine on
RewriteCond %{HTTP_HOST} ^domain\.com$ [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L]
RewriteCond %{QUERY_STRING} ^(ACT=.*)$ [NC]
RewriteRule ^(.*)$ index.php?%1 [L]
RewriteCond $1 !^(admin|index.php) [NC]
RewriteRule ^(.*) /index.php?/$1 [L]
Like this :
RewriteEngine On
RewriteBase /
RewriteCond $1 !^(index\.php|assets|thirdparty|admin|themes|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
Here is my site url structure as follows: http://www.sitename.com/new/about-us .
What I really want to do now is hide the directory name 'new' from the above url, but the admin url should remain unchanged.
The admin url would be like : http://www.sitename.com/new/admin .
My previous .htaccess code as follows:
RewriteEngine On
RewriteBase /new/
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/new/$1 [R=301,L]
RewriteRule blog/ - [L]
RewriteRule (^wlp) - [L]
RewriteRule admin/ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %(REQUEST_FILENAME} !-d
RewriteRule ^([\S\s/+.]+)/?$ index.php?url=$1 [QSA,L]
Here is my server directory structure:
/public
/new
.htaccess
index.php
about-us.php
/blog
/admin
Any help in this regard will be highly appreciated.
It sounds like what you are trying to accomplish is a common technique which I've seen before for forwarding all public_html requests to public_html/public to essentially hide the contents of the public_html directory from the user and making public_html/public the new web root.
Try using this in your public_html/.htaccess file (you can write further htaccess in public_html/new/.htaccess):
RewriteEngine on
RewriteBase /
#enforce www subdomain
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} ^sitename.com [NC]
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
#forward all requests, except new/admin, to the 'new' directory without the user's awareness
RewriteRule new/admin - [S=2]
RewriteRule ^$ new/ [L]
RewriteRule (.*) new/$1 [L]
This .htaccess in / should do:
RewriteEngine on
RewriteCond %{REQUEST_URI} !^new/
RewriteRule ^(.*)$ new/$1 [L]
I'm trying to force www on my website using a RewriteRule in the htaccess file.
I'm using FuelPHP and I have to have the following rewrite rule in the htaccess file but the methods I found to force www didn't play nice with my current setup.
Current htaccess code
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
Code that I found here to force www
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
How can I combine these to enable forcing www and still have the other rule in the htacess file?
Try using this:
RewriteEngine on
RewriteBase /
# Redirect to wwww
RewriteCond %{HTTP_HOST} !^www\.yourdomain\.com
RewriteRule (.*) http://www.yourdomain.com/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
FuelPHP comes with a .htaccess file in the public folder that contains a rewrite example for this situation.