How to convert .htaccess to web.config? - windows

I am realy lost here. I am used to work with linux server so I use .htaccess
Now I need to develop a project in windows server and I need to use some rewrite rules, etc. So I need to set the web.config file.
So I need help to convert my .htaccess rules to web.config
This are the rules:
RewriteEngine On
RewriteRule ^box/camp(.+)?/?$ /_box/access_box_files/camp$1
RewriteRule ^box/merchant(.+)?/?$ /box/access_box_files/merchant$1
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?url_tab=$1 [L,QSA]
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
UPDATE
RewriteRule ^box/camp(.+)?/?$ /_box/access_box_files/camp$1
In this case I need that whenever the URL is "/box/camp" there is access to "/_box/access_box_files/cam" and that all the information that comes in front of "(.+)?" "$1" is included. Without changing the URL in the browser, or forwarding the user.
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?url_tab=$1 [L,QSA]
In this case, any information that comes in the URL must be collected in a variable.
For example:
https:// website dot com/tab1/tab2/tab3
I will get the information in: $_GET['url_tab'] which would have the information: "tab1/tab2/tab3".
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
In this case it is to force the URL to be loaded with https.
Thank you all very much.

Related

Laravel redirect to HTTPS with .htaccess

I'm using Laravel 5.5.
Laravel has couple of .htaccess and in my case I'm working with .htaccess on root and inside the public folder.
All this time I was using this code in root .htaccess to setup the public folder:
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
and my website is loading when I enter the homepage.
After that, I wanted to force redirect all the pages using https. So, first when I try to put this code inside the root .htaccess it doesn't do anything. It keeps loading with http.
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Well, it makes sense, because when I setup the public folder, I have to put the redirect inside the .htaccess that is located inside the public folder.
OK, so I've tried like this now:
The root .htaccess:
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
The public .htaccess
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
This combination works. It does redirects to https.
But, there's one issue now. When I enter the homepage or if I open the website from the search results, the URL looks like this:
https://mywebsite.com/public/en
When I enter the other pages, I don't have issue related with the "public" path in the URL. So, let's say I want to open the contact page, the URL is https://mywebsite.com/en/contact. That's fine.
How can I avoid that "public" in my URL when I enter the homepage?
This should remove public from the url.
RewriteRule ^(.*)$ public/$1 [L]
I am not sure if this should go above
# Handle Front Controller...
or within it? Maybe try either one and see if either work?
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ public/$1 [L]
RewriteRule ^ index.php [L]
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
source

How to rewrite url to omit one parameter

I have the following url. I want to rewrite the following url to omit the "view" from the url.
Here is currently my existing mod rewrite
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?url=$1 [PT,L]
</IfModule>
http://example.com/page/view/helloworld
How do i rewrite the url to make it
http://example.com/page/helloworld
the keyword helloworld is dynamic.
Expert advice appreciated.
You might want to add the R=301 into the flags if you are worried about transfering SEO.
RewriteEngine On
RewriteRule ^(.+)/view/(.+)$ /$1/$2 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?url=$1 [PT,L]

htaccess file for codeigniter on subdomain virtualhost

i have problem about .htaccess file for my codeigniter installation.
On localhost this work fine, when i upload online its rewrite URL but the website not work.
this is my htaccess on localhost:
RewriteEngine On
RewriteBase /jCore_01/
#RewriteBase /
### Canonicalize codeigniter URLs
# If your default controller is something other than
# "welcome" you should probably change this
RewriteRule ^(welcome(/index)?|index(\.php)?)/?$ / [L,R=301]
RewriteRule ^(.*)/index/?$ $1 [L,R=301]
# Removes trailing slashes (prevents SEO duplicate content issues)
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/$ $1 [L,R=301]
# Enforce NO www
#RewriteCond %{HTTP_HOST} ^www [NC]
#RewriteRule ^(.*)$ http://domain.tld/$1 [L,R=301]
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
online i have a problem:
i put this file on subdomain jcore.miodomio.com and it rewrite URL but not work
example:
without htaccess it's work:
jcore.miodominio.com/index.php/en/home
with htaccess
jcore.miodominio.com/en/home
Not Found
The requested URL /en/home was not found on this server.
can anyone help me? suggestion?
regards
Denny
Try change your htaccess to:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/$1 [L]
Somethings to consider.
Did you enable Apache rewrite module?
If enabled check whether your virtual host file is configured properly So to make sure its hitting .htaccess or try putting some dump on .htacess , So if its hitting .htaccess than you should get an 500 server error.
If you are not getting error than its mostly the problem in your host settings.

Mod_rewrite to switch HTTP to HTTPS

I am trying to use a Bluehost supplied SSL wildcard certificate to switch one subdomain to HTTPS.
The web root contains many subdomains, and I only want to affect the test. subdomain.
Going into the web root, I've written the following .htaccess file:
RewriteCond %{SERVER_NAME} ^test.mydomain.com
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}$1
Yet hitting http://test.mydomain.com/admin/index.php does not redirect me to https://test.mydomain.com/admin/index.php.
Even cutting out the Condition of SERVER_NAME, it still doesn't work.
Is my rewrite rule bad?
Well, in the first place I was in the wrong .htaccess file. I needed to go to the directory for my subdomain.
Then, simply switching it from HTTP to HTTP apparently causes some kind of redirect to www. behavior.
I had to
A) Preserve the existing rules that were not intended for test.
B) Add the test. rules.
It added up to a lot.
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^test.example.com$
RewriteRule ^index\.php$ - [L]
RewriteCond %{HTTP_HOST} !^test.example.com$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteCond %{HTTP_HOST} ^test.example.com$
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
RewriteCond %{HTTP_HOST} ^test.example.com$
RewriteCond %{REQUEST_URI} !^/test/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) /test%{REQUEST_URI}
RewriteCond %{HTTP_HOST} ^test.example.com$
RewriteRule ^(/)?$ test/admin/index.php [L]

mod_rewrite: don't rewrite any subdomains

Is there a way to exempt any requests to a subdomain in mod_rewrite? Right now, I have a one-page app that's redirecting everything to index.html.
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !index
RewriteRule (.*) index.html [L]
</IfModule>
But I want to make sure that calls to subdomain.mydomain.com are permanently exempt from being rewritten.
You can use a condition on the subdomain and the - substitution to stop the rewriting. From http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html#rewriterule
There is a special substitution string named '-' which means: NO
substitution! This is useful in providing rewriting rules which only
match URLs but do not substitute anything for them.
Try
RewriteEngine On
RewriteCond %{HTTP_HOST} ^subdomain\.mydomain\.com$ [NC]
RewriteRule .* - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !index
RewriteRule (.*) index.html [L]

Resources