Can’t redirect using 301 and .htacces

I've just begun learning CSS and HTML.

I bought a domain from HostGator to upload my tiny website.

I used CyberDuck to upload all of my things.

Then I found out about a thing called .htacces which I did not have in the WWW folder and I've tried "making" one.

Then I tested the site using Nibbler and it keeps saying "There is duplicate content" and that I should do this: "Choose one domain that you would like to use and then set a permanent (HTTP 301) redirect to forward users who visit the other."

I found a lot of REWRITES AND REDIRECTS but I could not to make any of them work.

What do I need to write to not have a "duplicate" site (or to solve the Canonical Website Address (This is how it's called I think)) ???

Let's say my site name is: http://www.FirstSite.net and I want all "FirstSite" searches to go to https://FirstSite.net or FirstSite.net but still being a https.

I wrote https with an s because I want to make the site secure (if that is even possible).

I've been modifying the .htacces from gator's cPanel and I am using Google Chrome.

Thank you for reading this manuscript !

This is all that I've copy-paste into it (I forgot what those without a # do (the last 2 paragraphs)) :

# MAIN DEFAULTS
Options +ExecCGI -Indexes
DirectoryIndex index.html
DefaultLanguage en-US
AddDefaultCharset UTF-8
ServerSignature Off

# compress text, HTML, JavaScript, CSS, and XML
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
# remove browser bugs
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
Header append Vary User-Agent



#HTACCES Security
<Files ~ “^.*\.([Hh][Tt][Aa])”>
order allow,deny
deny from all
satisfy all
</Files>


# 1 WEEK 1 DAY
<filesMatch “.(jpg|jpeg|png|gif|swf|ico)$”>
Header set Cache-Control “max-age=691200, public”
</filesMatch>
# 1 WEEK 1 DAY
<filesMatch “.(xml|txt|js)$”>
Header set Cache-Control “max-age=691200, proxy-revalidate”
</filesMatch>
# 1 WEEK 1 DAY
<filesMatch “.(html|htm|css|php)$”>
Header set Cache-Control “max-age=691200, private, proxy-revalidate”
</filesMatch>

Options +SymLinksIfOwnerMatch 
RewriteEngine On 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
</IfModule>

Can’t redirect using 301 and .htacces

I've just begun learning CSS and HTML.

I bought a domain from HostGator to upload my tiny website.

I used CyberDuck to upload all of my things.

Then I found out about a thing called .htacces which I did not have in the WWW folder and I've tried "making" one.

Then I tested the site using Nibbler and it keeps saying "There is duplicate content" and that I should do this: "Choose one domain that you would like to use and then set a permanent (HTTP 301) redirect to forward users who visit the other."

I found a lot of REWRITES AND REDIRECTS but I could not to make any of them work.

What do I need to write to not have a "duplicate" site (or to solve the Canonical Website Address (This is how it's called I think)) ???

Let's say my site name is: http://www.FirstSite.net and I want all "FirstSite" searches to go to https://FirstSite.net or FirstSite.net but still being a https.

I wrote https with an s because I want to make the site secure (if that is even possible).

I've been modifying the .htacces from gator's cPanel and I am using Google Chrome.

Thank you for reading this manuscript !

This is all that I've copy-paste into it (I forgot what those without a # do (the last 2 paragraphs)) :

# MAIN DEFAULTS
Options +ExecCGI -Indexes
DirectoryIndex index.html
DefaultLanguage en-US
AddDefaultCharset UTF-8
ServerSignature Off

# compress text, HTML, JavaScript, CSS, and XML
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
# remove browser bugs
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
Header append Vary User-Agent



#HTACCES Security
<Files ~ “^.*\.([Hh][Tt][Aa])”>
order allow,deny
deny from all
satisfy all
</Files>


# 1 WEEK 1 DAY
<filesMatch “.(jpg|jpeg|png|gif|swf|ico)$”>
Header set Cache-Control “max-age=691200, public”
</filesMatch>
# 1 WEEK 1 DAY
<filesMatch “.(xml|txt|js)$”>
Header set Cache-Control “max-age=691200, proxy-revalidate”
</filesMatch>
# 1 WEEK 1 DAY
<filesMatch “.(html|htm|css|php)$”>
Header set Cache-Control “max-age=691200, private, proxy-revalidate”
</filesMatch>

Options +SymLinksIfOwnerMatch 
RewriteEngine On 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
</IfModule>

Virtual Hosts on Mac directing to ServerRoot

I was mainly using XAMPP for my local development needs, but I felt it time to take the crutches off and work from the command line interface.

The issue I am running into is that my virtual hosts are directing to the ServerRoot, and not where the virtual host points. The ones I'm trying currently are laravel apps, so my file structure is

/usr/local/var/www/domain1/laravel

/usr/local/var/www/domain1/public_html

Here is my config files

# /etc/apache2/httpd.conf
ServerRoot "/usr/local/var/www"
ServerName 127.0.0.1
DocumentRoot "/usr/local/var/www"

# /etc/apache2/extra/httpd-vhosts.conf
<VirtualHost *:80>
      DocumentRoot "/usr/local/var/www/mydomain.com/public_html"
      ServerName dev.mydomain
      ServerAlias www.dev.mydomain
      ErrorLog "/private/var/log/apache2/dev.mydomain/error_log"
      CustomLog "/private/var/log/apache2/dev.mydomain/access_log" common
</VirtualHost>

# /ect/hosts
127.0.0.1   localhost
127.0.0.1   dev.mydomain
::1         localhost
::1         dev.mydomain

When I go to dev.mydomain in the browser, it takes me to /usr/local/var/www instead of /usr/local/var/www/mydomain/public_html

I've already restarted the server.

Edit: When I traverse the file path, the php files are not parsing either and are opening as regular text files.

htaccess redirect folder to file works but keyword to file parameter don’t

I am working in a webapp in php and facing some challenges with the .htaccess redirections

This is my .htaccess file:

RewriteEngine On
# this works great
# sends request for domain.com/page/id -> domain.com/page.php?id=id 
RewriteRule ^page/([^/]*)$ /page.php?id=$1 [L]
RewriteRule ^etc/([^/]*)$ /etc.php?id=$1 [L]

# this has to sent domain.com/username to -> domain.com/user.php?id=username 
# but don't work
RewriteRule ^([^/]*)$ /user.php?id=$1 [L]

What i am doing wrong?

remove subdir from url with rewrite rule

I move my main domain from public_html/ to public_html/subdir/

My current htaccess is :

RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_URI} !^/subdir/
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.
RewriteRule ^(.*)$ /subdir/$1 [L]

When I called my APi before it was : domain.com/api/

But now it's : domain.com/subdir/api/

How to remove the "subdir" in the url to keep my api like previous ? But still point the root to my subdir with my current htaccess ?

Thanks

Apache serves "/" but 404 all other url [duplicate]

This question already has an answer here:

I built a php site using the built in server. I experienced none of the problems I am now facing when using Apache.

Folder structure:

app -> index.php

controllers -> home.php

views -> home.php

I have Apache successfully serving the home page at "/" but any other page I visit returns a 404. Inside "index.php" is a "switch ($_SERVER['REQUEST_URI'])" statement. A visit to the URI called the controller which in turn calls the view:

switch ($_SERVER['REQUEST_URI'])
{
  case '/':
    home_controller::home();
    break;

  case '/signup':
    signup_controller::signup();
    break;
}

If I try to visit the "signup page" at "/signup" I get a 404. I'm not sure why this is the case. I don't know Apache that well but spent a lot of time trying to figure this out. Rewrite didn't fix the problem but I could have been doing it wrong. Any information would be much appreciated.

Edit 1 Modrewrite may solve the problem but it did not before. As stated I don't know Apache that well so finding the correct terminology may be tripping me up.

My PHP program takes the REQUEST_URI and has a router built in that matches on a switch statement. My logic was that any uri that goes to Apache would in turn go to PHP. I did nothing to make "/" work correctly. Not sure why I need to do something different to make "/signup" work.

apache doesn’t find the web installer file

When I enter http://w.x.y.z in firefox from a remote machine where w.x.y.z. is a valid IP, I get the following error

The requested URL /install was not found on this server.

However, at the same time, if I run php -S http://w.x.y.z:8080 and then enter http://w.x.y.z:8080 in firefox from the same remove machine, everything work fine.

[email protected]:/var/www/html# php -S 5.57.36.104:8080
PHP 7.2.5-0ubuntu0.18.04.1 Development Server started at Wed May 30 01:29:44 2018
Listening on http://5.57.36.104:8080
Document root is /var/www/html
Press Ctrl-C to quit.
[Wed May 30 01:30:00 2018] 37.32.42.129:61857 [301]: /
[Wed May 30 01:30:00 2018] 37.32.42.129:61858 [301]: /install
[Wed May 30 01:30:01 2018] 37.32.42.129:61859 [200]: /install/rules
[Wed May 30 01:30:01 2018] 37.32.42.129:61860 [200]: /ow_install /view/style.css
[Wed May 30 01:30:01 2018] 37.32.42.129:61861 [200]: /ow_install/view/img/FARSISans/FARSISansExpanded.woff2
[Wed May 30 01:30:01 2018] 37.32.42.129:61862 [200]: /ow_install/view/img/FARSISans/FARSISans-Bold.woff2
[Wed May 30 01:30:01 2018] 37.32.42.129:61863 [200]: /ow_install/view/img/header.png
[Wed May 30 01:30:01 2018] 37.32.42.129:61864 [200]: /ow_install/view/img/logo.png

The content of apache config file is

[email protected]:/var/www/html# cat /etc/apache2/sites-available/000-default.conf 
<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot /var/www/html/
<Directory "/var/www/html/">
 Options Indexes FollowSymLinks MultiViews
 AllowOverride All
 Order allow,deny
 allow from all
 Require all granted
</Directory>
LogLevel debug 
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

As you can see it correctly finds the files and I can see the install page. Why that happens and how can I fix that?