to remove /public/ from laravel , I used the following code
RewriteEngine on
RewriteCond %{HTTP_HOST} ^site.comn$ [NC,OR]
RewriteCond %{HTTP_HOST} ^site.com$
RewriteCond %{REQUEST_URI} !public/
RewriteRule ^(.*) /public/$1 [L]
But the issue is now that I can't even access files saved under site.com/files/image.png or anything like that. It shows me 404 page.
How to modify htaccess to allow access to some directories. Kindly help.
This is because you are redirecting everything to /public/. You need to exclude your existent dirs and files from the redirect.
RewriteEngine on
RewriteCond %{HTTP_HOST} ^site.comn$ [NC,OR]
RewriteCond %{HTTP_HOST} ^site.com$
RewriteRule ^/?$ /public/ [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !^/public/
RewriteRule ^(.*) /public/$1 [L]
Related
I want to remove upload folder from opencart URL. I have tried with following code
RewriteEngine on
RewriteBase /
# Redirect non-www to www
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
# Route all request to production folder
#RewriteRule ^(.*)$ upload/$1[L]
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?siteName.ae$
RewriteCond %{REQUEST_URI} !^upload/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ upload/$1
RewriteCond %{HTTP_HOST} ^(www.)?siteName.ae$
RewriteRule ^(/)?$ upload/ [L]
But when I adding this code then login does not working.
Try this one:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !^/upload/
RewriteRule ^(.*)$ /upload/$1 [L]
You need to change the rewrite base to /{foldername here}/
We have moved our site to a subdomain while on the main domain we have a new site with new url's. What we are trying to do is having the old url's redirect to the subdomain while the excluding the new url's.
here's examples of the old url's:
http://www.domain.co.il/index.php?dir=app_admin&page=ip_stat&op=list&pos=0
should be redirected to:
http://sub.domain.co.il/index.php?dir=app_admin&page=ip_stat&op=list&pos=0
While the new site url's (do not contain php) and the homepage should not be effected.
This is what our htaccess looks like:
It does redirect the url's to the sub, but does not exclude the new pages and redirect them to the subdomain home (sub.domain.com)
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [QSA,L]
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteCond %{REQUEST_URI} !contact(|$)
RewriteCond %{REQUEST_URI} !about(|$)
RewriteCond %{REQUEST_URI} index\.php
RewriteRule ^(.*)$ http://sub.domain.com [R=301,L]
Hopefully someone can help us get this right, we get many 404 in our gwt now :/
Thanks for any help !
Fix some regex and reorder your rules:
RewriteEngine on
RewriteBase /
RewriteCond %{THE_REQUEST} !/(contact|about) [NC]
RewriteCond %{THE_REQUEST} !\.(jpe?g|gif|bmp|png|tiff|css|js) [NC]
RewriteRule ^(.+)$ http://sub.domain.com/$1 [R=301,L,NE]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [L]
Also test this in a new browser to avoid old browser cache.
Here's the full code for the site.
The way things are set up is that the new site is being called from a folder named "main" while the old site is being called from the root directory.
So we actually have 2 htaccess.
Here's the root htaccess code:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^/([^.]+)\.php
RewriteRule ^(.*)$ http://sub.domain.com/$1 [L,R=301]
RewriteCond %{HTTP_HOST} www.domain.com$
RewriteCond %{REQUEST_URI} !^/main
RewriteRule ^(.*)$ /main/$1 [L]
RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteRule .* - [L]
RewriteRule ^admin$ index.php?dir=app_misc&page=login [L]
RewriteRule ^admin/$ index.php?dir=app_misc&page=login [L]
RewriteRule ^sitemap.xml$ sitemap.php [L]
RewriteRule ^robots.txt$ robots.php [L]
RewriteRule ^adv$ adv/index.php [L]
RewriteRule ^adv/$ adv/index.php [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^/(([0-9]+)_([^/]+)|([0-9]+))$
RewriteRule (.*) /404.php?a=%{REQUEST_URI} [L]
and the htaccess in the "main" folder:
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_URI} !(contact|about) [NC]
RewriteRule ^(.*)$ http://sub.domain.com/$1 [R=301,L,NE]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [L]
I've tested on few browsers and in incognito mode as well
Thanks
Instead of excluding urls which caused necessary css & js files to redirect as well, I solved it by creating a redirect that effect only url's with php.
RewriteCond %{THE_REQUEST} ([^.]+)\.php [NC]
RewriteRule ^(.*)$ http://sub.domain.com/$1 [R=301,L,NE]
I have problem with my rewrite rule. I have new webpage in root/hrp. and if i open pages in that directory, then all is OK, but when i wanna surf those pages from root (without /hrp/) then is problem. I found some .htaccess rules and all working fine, but if i wanna execute some pdf,jpg,or php script directly, then come problem.
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_URI} !hrp/
RewriteRule (.*) /hrp/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/hrp/index.php
RewriteRule ^(.*)$ /index.php [L]
if i put this bottom code on begining, i can open files directli, but pages don't work and vice versa
RewriteCond %{REQUEST_FILENAME} (/|\.php|\.html|\.htm|\.png|\.jpg|\.jpeg|\.gif|\.xml|\.rss|\.feed|\.pdf|\.raw|/[^.]*)$ [NC]
RewriteRule ^(.+)$ $1 [L]
Try adding this at the top instead:
RewriteRule \.(php|html?|png|jpe?g|gif|xml|rss|feed|pdf|raw)$ - [L,NC]
or you can try adding this condition to your hrp rule:
RewriteCond %{DOCUMENT_ROOT}/hrp/$1 -f [OR]
RewriteCond %{DOCUMENT_ROOT}/hrp/$1 -d
RewriteRule (.*) /hrp/$1 [L]
I have find solution
don't rewrite this files
RewriteCond %{REQUEST_URI} !.(gif|jpg|png|ico|css|js|swf|wav|mp3|less|cur|pdf|jpeg|txt|ico|zip|gz) [NC]
don't rewrite this folder - there i have php files, and dont rewrite this files
RewriteCond %{REQUEST_URI} !(folder1|folder2|file1.php|file2.php|file3.php) [NC]
all content is in "/hrp/" folder
RewriteCond %{REQUEST_URI} !hrp/
RewriteRule (.*) /hrp/$1 [L]
but url don't contains "/hrp/"
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/hrp/index.php
RewriteRule (.*) /index.php [L]
I have a domain that shows different pages if I leave out the www. Without the www the page freezes, so I want to redirect the http://example.com to http://www.example.com
My question is, how do I change the htaccess so it redirects to the www version?
Here is my .htaccess:
DirectoryIndex index.php
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|robots\.txt)
RewriteRule ^(.*)$ index.php?/$1 [L]
Add these lines after RewriteEngine On:
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
But keep in mind, making redirecting rule is just a compromise for your application, not solution for your page freezing problem.
A friend solved my problem by adding the following code underneath the existing code:
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
Now everything works perfectly! The complete .htaccess file now looks like:
DirectoryIndex index.php
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|robots\.txt)
RewriteRule ^(.*)$ index.php?/$1 [L]
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
I have 2 websites: one site that located in the root of the public html folder and another site located in WFM subfolder, the WFM subfolder is facing some problem which is unable to redirect to the correct page that instead of displaying the contents in domain.com.sg/careers, it is reloading the home page instead.
The strange part is the images, JS and CSS return 200 OK although the files contains the content of index.php. Tested through Google Chrome web developer tools.
domain.com.sg is just a dummy url.
Code on /home/webfire/public_html/.htaccess
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
IndexIgnore *
Options All -Indexes
IndexOptions +SuppressHTMLPreamble
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com.sg #Not working correctly
RewriteCond %{REQUEST_URI} !^/wfm #Not working correctly
RewriteRule ^(.*)$ /wfm/$1 [L] #Not working correctly
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^([^\.]+)$ $1.php [NC,L]
RewriteCond %{REQUEST_FILENAME} !-f #For website located in the public_html folder
RewriteCond %{REQUEST_FILENAME} !-d #For website located in the public_html folder
RewriteRule ^(.*)$ index.php/$1/ [L] #For website located in the public_html folder
RewriteCond %{REQUEST_METHOD} ^PUT$ [OR]
RewriteCond %{REQUEST_METHOD} ^MOVE$
RewriteRule ^/files/(.*)\.php /files/$1.nophp
RewriteCond %{HTTP_REFERER} !^http://domain.com.sg/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://domain.com.sg$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.domain.com.sg/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.domain.com.sg$ [NC]
RewriteRule .*\.(jpg|jpeg|gif|png|bmp)$ - [F,NC]
Try this code:
IndexIgnore *
Options All -Indexes
IndexOptions +SuppressHTMLPreamble
RewriteEngine On
RewriteBase /
# existing rule to block images hot linking
RewriteCond %{HTTP_REFERER} !^http://domain.com.sg/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://domain.com.sg$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.domain.com.sg/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.domain.com.sg$ [NC]
RewriteRule .*\.(jpg|jpeg|gif|png|bmp)$ - [F,NC]
# for subdomain forward to /wfm/
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com\.sg$
RewriteRule ^((?!wfm/).*)$ /wfm/$1 [L,NC]
# existing rule to handle PUT/MOVE reqquest
RewriteCond %{REQUEST_METHOD} ^PUT$ [OR]
RewriteCond %{REQUEST_METHOD} ^MOVE$
RewriteRule ^files/(.*)\.php /files/$1.nophp [L]
# is PHP file exists for given URI then use it
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^([^.]+)/?$ $1.php [L]
# forward rest to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1/ [L]