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]
Related
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]
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}/
how do I setup med .htaccess file, so it will rewrite www.mydomain.com/index.php?page=home to www.mydomain.com/home?
I have tried this piece of code, but it doesn't like i want.
RewriteEngine On
RewriteBase /
# Removes index.php from ExpressionEngine URLs
RewriteCond %{THE_REQUEST} ^GET.*index\.php?page= [NC]
RewriteCond %{REQUEST_URI} !/system/.* [NC]
RewriteRule ^([^/]+)/? index.php [L,QSA]
# Directs all EE web requests through the site index file
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?page=$1 [L]
Your first redirect rule in not right. You can use:
RewriteEngine On
RewriteBase /
# Removes index.php from ExpressionEngine URLs
RewriteCond %{THE_REQUEST} /index\.php\?page=([^\s&]+) [NC]
RewriteCond %{REQUEST_URI} !/system/.* [NC]
RewriteRule ^ /%1? [R=302,L,NE]
# Directs all EE web requests through the site index file
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ /index.php?page=$1 [L,QSA]
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 need to redirect all pages for a domain to a subpage called 'emergency'.
However ignore two specific pages - the 'emergency' page itself and another page called 'system'.
I currently have:
AcceptPathInfo On
Options -Indexes
RewriteEngine On
RewriteBase /
RewriteCond %{REMOTE_ADDR} !^111\.111\.111\.111
RewriteCond %{REQUEST_URI} !^/(emergency|system)/?$ [NC]
RewriteRule ^ /emergency? [L,R=301]
RewriteCond $1 !^(index\.php|assets|robots\.txt|cgi-bin|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^/index.php
RewriteCond $1 !.(css|js|png|jpe?g|gif|ico)$ [NC]
RewriteRule ^(.*)$ /index.php?/$1 [L]
This does not work.
I have already looked at, but could not get anything working either:
Apache redirect all sub pages to home page except specific pages
.htaccess 301 redirect that excludes a subpage
Any help would be appreciated!
Thanks!
There is a leading slash after ^
Try this rule:
RewriteEngine On
RewriteBase /
RewriteCond %{REMOTE_ADDR} !^111\.111\.111\.111
RewriteCond %{REQUEST_URI} !^/(emergency|system)/?$ [NC]
RewriteRule ^ /emergency? [L,R=301]
Your full and corrected .htaccess
AcceptPathInfo On
Options -Indexes
RewriteEngine On
RewriteBase /
RewriteCond %{REMOTE_ADDR} !^111\.111\.111\.111
RewriteCond %{REQUEST_URI} !^/(index\.php|emergency|system)/?$ [NC]
RewriteRule ^.+$ /emergency? [L,R=301]
RewriteCond $1 !^(index\.php|assets|robots\.txt|cgi-bin|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^/index.php
RewriteCond $1 !.(css|js|png|jpe?g|gif|ico)$ [NC]
RewriteRule ^(.*)$ /index.php?/$1 [L]