proper userdir.conf for this .htaccess - .htaccess

The story behind...
Ok, I was experimenting things with my netbook...without having backup files. Yes, I'm a moron :D
The Problem
I have this .htaccess file in my userdir which was working properly before I screwed up my partion:
Options +FollowSymLinks
RewriteEngine On
RewriteBase /~dierre/DierReLabS/
RewriteRule ^(tutorials|me|not-found|add)$ $1/ [R=301,L]
RewriteRule ^me/$ me.php [L]
RewriteRule ^style/$ style.css [L]
RewriteRule ^logo/$ logo2.png [L]
RewriteRule ^add/$ add.php [L]
RewriteRule ^tutorials/$ tutorials.php [L]
RewriteRule ^tutorial/([a-zA-Z0-9\-]+)/$ tutorial.php?tut=$1 [L]
RewriteRule ^not-found/$ 404.php [L]
# This is a real directory...
RewriteCond %{REQUEST_FILENAME} -f [OR]
# Or it's a real file...
RewriteCond %{REQUEST_FILENAME} -d
# And it's not not-found/...
RewriteCond $0 !=not-found/
# And it's not the root
RewriteCond $0 !=""
# And it's not any of the above due to an internal redirect...
RewriteCond %{ENV:REDIRECT_STATUS} ^$
# So cause a 404 response (you could redirect to 404.php if you want)
RewriteRule ^.*$ - [R=404,L]
ErrorDocument 404 /~dierre/DierReLabS/not-found/
In the userdir this .htaccess does not work properly with the default parameters in userdir.conf. I do not have anymore that configuration. The current configuration is:
<IfModule mod_userdir.c>
UserDir public_html
UserDir disabled root
<Directory /home/*/public_html>
AllowOverride FileInfo AuthConfig Limit Indexes
Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec
<Limit GET POST OPTIONS>
Order allow,deny
Allow from all
</Limit>
<LimitExcept GET POST OPTIONS>
Order deny,allow
Deny from all
</LimitExcept>
</Directory>
</IfModule>
I really can't recall what I did. Can you help me?

Thanks God for forsaken laptop! I've started today my Thinkpad and it was there the configuration with a non-updated version of the site.
<IfModule mod_userdir.c>
UserDir public_html
UserDir disabled root
<Directory /home/*/public_html>
#AllowOverride FileInfo AuthConfig Limit Indexes
AllowOverride All
#Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec
Options Indexes FollowSymLinks
<Limit GET POST OPTIONS>
Order allow,deny
Allow from all
</Limit>
<LimitExcept GET POST OPTIONS>
Order deny,allow
Deny from all
</LimitExcept>
</Directory>
</IfModule>

Related

.htaccess subfolder no redirect correctly - Error 404

I have a wordpress installation in the root of my server, I wanted to use the "opensourcepos" script in a new directory called "ospos"
If I try to access the link
www.mysite.it/ospos/
I am redirected to
www.mysite.it/public
with 404 error
To access the ospos installation I have to go to
www.mysite.it/ospos/public
only in this way everything works correctly.
Maybe there is some instruction in the ospos folder .htaccess file
which does not redirect correctly.
Code .htaccess wordpress /root
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Code .htaccess root/ospos
# redirect to public page
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI} !^public$
RewriteCond %{REQUEST_URI} !^/.well-known/acme-challenge [NC]
RewriteRule "^(.*)$" "/public/" [R=301,L]
</IfModule>
# disable directory browsing
# For security reasons, Option all cannot be overridden.
Options +ExecCGI +Includes +IncludesNOEXEC +SymLinksIfOwnerMatch -Indexes
# prevent folder listing
IndexIgnore *
# Apache 2.4
<IfModule authz_core_module>
# secure htaccess file
<Files .htaccess>
Require all denied
</Files>
# prevent access to PHP error log
<Files error_log>
Require all denied
</Files>
# prevent access to LICENSE
<Files LICENSE>
Require all denied
</Files>
# prevent access to csv, txt and md files
<FilesMatch "\.(csv|txt|md|yml|json|lock)$">
Require all denied
</FilesMatch>
</IfModule>
# Apache 2.2
<IfModule !authz_core_module>
# secure htaccess file
<Files .htaccess>
Order allow,deny
Deny from all
Satisfy all
</Files>
# prevent access to PHP error log
<Files error_log>
Order allow,deny
Deny from all
Satisfy all
</Files>
# prevent access to LICENSE
<Files LICENSE>
Order allow,deny
Deny from all
Satisfy all
</Files>
# prevent access to csv, txt and md files
<FilesMatch "\.(csv|txt|md|yml|json|lock)$">
Order allow,deny
Deny from all
Satisfy all
</FilesMatch>
</IfModule>
Code .htaccess root/ospos/public
RewriteEngine On
# To redirect a subdomain to a subdir because of https not supporting wildcards
# replace values between <> with your ones
# RewriteCond %{HTTP_HOST} ^<OSPOS subdomain>\.<my web domain>\.com$ [OR]
# RewriteCond %{HTTP_HOST} ^www\.<OSPOS subdomain>\.<my web domain>\.com$
# RewriteRule ^/?$ "https\:\/\/www\.<my web domain>\.com\/<OSPOS path>" [R=301,L]
# To rewrite "domain.com -> www.domain.com" uncomment the following lines.
# RewriteCond %{HTTPS} !=on
# RewriteCond %{HTTP_HOST} !^www\..+$ [NC]
# RewriteCond %{HTTP_HOST} (.+)$ [NC]
# RewriteRule ^(.*)$ http://www.%1/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# if in web root
# RewriteRule ^(.*)$ index.php?/$1 [L]
# if in subdir comment above line, uncomment below one and replace <OSPOS path> with your path
RewriteRule ^(.*)$ /ospos/public/index.php?/$1 [L]
# disable directory browsing
# For security reasons, Option all cannot be overridden.
#Options All -Indexes
Options +ExecCGI +Includes +IncludesNOEXEC +SymLinksIfOwnerMatch -Indexes
# prevent folder listing
IndexIgnore *
# Apache 2.4
<IfModule authz_core_module>
# secure htaccess file
<Files .htaccess>
Require all denied
</Files>
# prevent access to PHP error log
<Files error_log>
Require all denied
</Files>
</IfModule>
# Apache 2.2
<IfModule !authz_core_module>
# secure htaccess file
<Files .htaccess>
Order allow,deny
Deny from all
Satisfy all
</Files>
# prevent access to PHP error log
<Files error_log>
Order allow,deny
Deny from all
Satisfy all
</Files>
</IfModule>
<IfModule mod_expires.c>
<FilesMatch "\.(jpe?g|png|gif|js|css)$">
ExpiresActive On
ExpiresDefault "access plus 1 week"
</FilesMatch>
</IfModule>
I have read many questions and made many tests, but I still haven't been able to figure out where and what to change to make it redirect correctly.
Anyone have any suggestions on this?
Thank you
PHP version: 7.3.13
MySQL version: 5.6.44-86.0
OS and version: CentOS 7
WebServer is: Apache 2.4
How should I edit:
RewriteCond %{REQUEST_URI} !^public$
RewriteCond %{REQUEST_URI} !^/.well-known/acme-challenge [NC]
RewriteRule "^(.*)$" "/public/" [R=301,L]

Deploying Laravel on openSUSE: api routes not working

I Deployed a Laravel web application on a Tumbleweed openSUSE. I can access all routes defined in routes/web.php, but all routes in routes/api.php returned 404 not found.
Here's my apache2 httpd.conf file:
Include /etc/apache2/uid.conf
Include /etc/apache2/server-tuning.conf
<IfDefine !SYSCONFIG>
Include /etc/apache2/loadmodule.conf
</IfDefine>
<IfDefine !SYSCONFIG>
Include /etc/apache2/global.conf
</IfDefine>
Include /etc/apache2/mod_status.conf
Include /etc/apache2/mod_info.conf
Include /etc/apache2/mod_reqtimeout.conf
Include /etc/apache2/mod_cgid-timeout.conf
Include /etc/apache2/mod_usertrack.conf
Include /etc/apache2/mod_autoindex-defaults.conf
TypesConfig /etc/apache2/mime.types
Include /etc/apache2/mod_mime-defaults.conf
Include /etc/apache2/errors.conf
Include /etc/apache2/ssl-global.conf
# forbid access to the entire filesystem by default
<Directory />
Options None
AllowOverride All
<IfModule !mod_access_compat.c>
Require all denied
</IfModule>
<IfModule mod_access_compat.c>
Order deny,allow
allow from all
</IfModule>
</Directory>
<Directory "/srv/www">
AllowOverride All
</Directory>
AccessFileName .htaccess
<Files ~ "^\.ht">
<IfModule !mod_access_compat.c>
Require all denied
</IfModule>
<IfModule mod_access_compat.c>
Order allow,deny
allow from all
</IfModule>
</Files>
DirectoryIndex index.html index.html.var
Include /etc/apache2/default-server.conf
and this is my .htaccess file I put inside the htdocs folder
<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>
I hope someone can help me on this. I'm pretty new to linux especially openSUSE. Also, I'm sorry for my bad English.
If you are defining routes inside api.php, then your URL should be called prefix as API:
http://someurl.com/api/get/user

Debug .htaccess syntax error

I have the following code:
# Rewrite to www
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^salom.dev[nc]
RewriteRule ^(.*)$ http://www.salom.dev/$1 [r=301,nc]
# 301 Redirect Entire Directory
RedirectMatch 301 /admin(.*) /vendor/aheinze/cockpit/$1
# Change default directory page
DirectoryIndex /site
# Prevent viewing of .htaccess file
<Files .htaccess>
order allow,deny
deny from all
</Files>
# Prevent directory listings
Options All -Indexes
I keep getting 500 errors but I can't find the problem any ideas?
Here is the conf file:
<VirtualHost *:80>
ServerAdmin webmaster#localhost
ServerName salom.dev
DocumentRoot /home/otis/Developer/salom
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory /home/otis/Developer/salom/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>
Also is there a way to debug these errors using the dev tools or potentially the logs?
DirectoryIndex is a file not a directory and you have a missing space before `[nc].
Try this .htaccess:
# Change default directory page
# DirectoryIndex /site
# Rewrite to www
Options +FollowSymLinks -Indexes
RewriteEngine on
RewriteCond %{HTTP_HOST} ^salom\.dev$ [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
# 301 Redirect Entire Directory
RewriteRule ^admin(.*) /vendor/aheinze/cockpit/$1 [L,NC,R=301]
# Prevent viewing of .htaccess file
<Files .htaccess>
order allow,deny
deny from all
</Files>

How to enable/modify phpbb url to work just like html?

I have installed phpbb 3.1.4 newly.. Currently my web urls are like this http:// mydomain.com/viewtopic.php?f=6&p=6#p6
How can i force it to use
http:// mydomain.com/mytopics.html
I have tried editing .htaccess but still its hope less..
My default htaccess
<IfModule mod_rewrite.c>
RewriteEngine on
#
# Uncomment the statement below if you want to make use of
# HTTP authentication and it does not already work.
# This could be required if you are for example using PHP via Apache CGI.
#
#RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]
#
# The following 3 lines will rewrite URLs passed through the front controller
# to not require app.php in the actual URL. In other words, a controller is
# by default accessed at /app.php/my/controller, but can also be accessed at
# /my/controller
#
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ app.php [QSA,L]
#
# If symbolic links are not already being followed,
# uncomment the line below.
# http://anothersysadmin.wordpress.com/2008/06/10/mod_rewrite-forbidden-403-with-apache-228/
#
#Options +FollowSymLinks
</IfModule>
# With Apache 2.4 the "Order, Deny" syntax has been deprecated and moved from
# module mod_authz_host to a new module called mod_access_compat (which may be
# disabled) and a new "Require" syntax has been introduced to mod_authz_host.
# We could just conditionally provide both versions, but unfortunately Apache
# does not explicitly tell us its version if the module mod_version is not
# available. In this case, we check for the availability of module
# mod_authz_core (which should be on 2.4 or higher only) as a best guess.
<IfModule mod_version.c>
<IfVersion < 2.4>
<Files "config.php">
Order Allow,Deny
Deny from All
</Files>
<Files "common.php">
Order Allow,Deny
Deny from All
</Files>
</IfVersion>
<IfVersion >= 2.4>
<Files "config.php">
Require all denied
</Files>
<Files "common.php">
Require all denied
</Files>
</IfVersion>
</IfModule>
<IfModule !mod_version.c>
<IfModule !mod_authz_core.c>
<Files "config.php">
Order Allow,Deny
Deny from All
</Files>
<Files "common.php">
Order Allow,Deny
Deny from All
</Files>
</IfModule>
<IfModule mod_authz_core.c>
<Files "config.php">
Require all denied
</Files>
<Files "common.php">
Require all denied
</Files>
</IfModule>
</IfModule>
Please guide me, how to fix this?
Update : I have tried adding below in my htaccess .. No difference
RewriteEngine On
RewriteCond %{REQUEST_URI} !\.[a-zA-Z0-9]{3,4}
RewriteCond %{REQUEST_URI} !/$
RewriteRule ^(.*)$ $1.html
Above codes copy pasted from From ReWrite rule to add .html extension
And also tried adding
RewriteCond %{REQUEST_URI} !^.*.php$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ $1.html [L,R=301]
and also tried adding (Source)
RewriteBase /
RewriteRule ^(.*)-f([0-9]*)/(.*)-t([0-9]*)-s([0-9]*).html viewtopic.php?f=$2&t=$4&start=$5&%{QUERY_STRING} [L]
RewriteRule ^(.*)-f([0-9]*)/(.*)-t([0-9]*).html viewtopic.php?f=$2&t=$4&%{QUERY_STRING} [L]
RewriteRule global/(.*)-t([0-9]*).html ./viewtopic.php?f=1&t=$2&%{QUERY_STRING} [L]
RewriteRule ^(.*)-f([0-9]*)/index-s([0-9]*).html viewforum.php?f=$2&start=$3&%{QUERY_STRING} [L]
RewriteRule ^(.*)-f([0-9]*)/ viewforum.php?f=$2&%{QUERY_STRING} [L]
RewriteRule ^(.*)-f([0-9]*) viewforum.php?f=$2&%{QUERY_STRING} [L]
RewriteRule ^forum.html index.php?%{QUERY_STRING} [L]
Just wish to share this.. Looks like there is no way to do this using htaccess.. It was confirmed by KevC - Support Team Member Phpbb
https://www.phpbb.com/community/viewtopic.php?f=466&t=2319241

.htaccess not routing to /public_html/

I seem to be having an interesting problem in that .htaccess isn't routing to /public_html/index.html by default as it should, and I'm getting a page not found error. I do know that someone tampered with the file recently but have no idea what they did and I unfortunately know nothing about routing. I tried to do some research but didn't come up with anything that gave a solution to my predicament. Does anyone know how to go about making the server route to public_html? Here's what I have right now.
RewriteEngine on
IndexIgnore .htaccess */.??* *~ *# */HEADER* */README* */_vti*
<Limit GET POST>
order deny,allow
deny from all
allow from all
</Limit>
<Limit PUT DELETE>
order deny,allow
deny from all
</Limit>
AuthName evolvingwebcreations.com
#-------------------------
RewriteCond %{HTTP_HOST} ^swinkapps.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.swinkapps.com$
RewriteRule ^(.*) "http\:\/\/127\.0\.0\.1\:12005\/$1" [P,L]
#-------------------------
RewriteCond %{HTTP_HOST} ^swinkapps.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.swinkapps.com$
RewriteRule ^clients(.*) "http\:\/\/127\.0\.0\.1\:12005\/$1" [P,L]
Thanks in advance!
I don't believe it ever routes to public_html by default. You'll need to specify
UserDir public_html
and possibly set some access permissions such as
<Directory /home/*/public_html>
AllowOverride FileInfo AuthConfig Limit
Options Indexes SymLinksIfOwnerMatch IncludesNoExec
</Directory>

Resources