I need help.
I've wasted half hour to get my mod_rewrite rule. Unsuccessfully.
My server root structure is:
/project/public_html/index.html
/project/public_html/css/style.css
/project/public_html/js/script.js
I want to access it from my localhost as:
/project/index.html
/project/css/style.css
/project/js/script.js
I have this in my /project/.htaccess:
RewriteEngine On
RewriteBase /project
RewriteRule ^(.+)$ public_html/$1 [L,QSA,NS]
But I'm still getting this:
[Thu Dec 05 12:29:20.252091 2013] [core:error] [pid 26176] [client 127.0.0.1:60642] AH00124: Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace.
And actually is happening this:
[Thu Dec 05 12:29:20.252111 2013] [core:debug] [pid 26176] core.c(3520): [client 127.0.0.1:60642] AH00122: redirected from r->uri = /project/public_html/public_html/public_html/public_html/public_html/public_html/public_html/public_html/public_html/index.html
Problem should be extremely simple, but neither Google, nor manual helped me.
Thanks in advance.
Try this rule with an additional condition to stop looping. This condition first checks whether /public_html has already been inserted into request URI.
RewriteEngine On
RewriteBase /project/
RewriteCond %{REQUEST_URI} !/public_html/ [NC]
RewriteRule ^(.*)$ public_html/$1 [L,NS]
Related
I have googled but most uses are when person knows their URLs yet i want to redirect all possible URLs that give 404/503 errors with 301 to main domain.
Preferably htaccess since site is html.
So any request to page domain.com/XXXX that doesnt exist should redirect to main instead of giving errors ie:
Not Found
The requested URL /eafsdg was not found on this server.
To redirect all non existent and 503 requests to newdomain, you can use
ErrorDocument 404 http://newdomain.com/
ErrorDocument 503 http://newdomain.com/
In NGINX it would be like this :
NOTE: Since I use and I think a lot of people use NGINX as a proxy server, this won't redirect bad pages if the location is a proxy, that needs to be configured on the actual server, so I ended up using starkeen's answer on the end Apache server, but thought id share for NGINX.
error_page 404 /custom_404.html;
location = /custom_404.html {
root /usr/share/nginx/html;
internal;
}
or
error_page 404 /;
location = / {
root /usr/share/nginx/html;
internal;
}
https://www.digitalocean.com/community/tutorials/how-to-configure-nginx-to-use-custom-error-pages-on-ubuntu-14-04
Try this .htaccess code to redirect all 404 page to homepage:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . / [L,R=301]
thanks in advance, this is an odd problem, but probably is some internal processing I don't understand...
The rules and conditions work as expected except for one tiny problem.... it seems to be returning an empty file when the file is not empty...
On the bright side I got logging working, and am starting to have a clue about the very cryptic codes (thank you mr. apache and of course apache.org, and for those who want to test there regex: regex101.com)
Here is my log file:
[Sat Dec 06 19:04:49.939312 2014] [rewrite:trace1] [pid 5918] mod_rewrite.c(468): [client 192.168.1.100:55227] 192.168.1.100 - - [webtypography.dev/sid#7fdcea80dd68][rid#7fdcea7de0a0/initial] [perdir /var/www/webtypography.dev/public_html/] pass through /var/www/webtypography.dev/public_html/toc.php
this is my .htaccess file:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^webtypography\.dev$ [NC]
RewriteRule ^(.*)\/$ $1.php [R=301,L]
A little more info: My intent is if you type in the url which includes a directory: /directory/ it is rewritten as directory.php and appended to the base url....works great except the big blank browser viewport...
[Sat Dec 06 19:04:49.939265 2014] [rewrite:trace3] [pid 5918] mod_rewrite.c(468): [client 192.168.1.100:55227] 192.168.1.100 - - [webtypography.dev/sid#7fdcea80dd68][rid#7fdcea7de0a0/initial] [perdir /var/www/webtypography.dev/public_html/] strip per-dir prefix: /var/www/webtypography.dev/public_html/toc.php -> toc.php
[Sat Dec 06 19:04:49.939301 2014] [rewrite:trace3] [pid 5918] mod_rewrite.c(468): [client 192.168.1.100:55227] 192.168.1.100 - - [webtypography.dev/sid#7fdcea80dd68][rid#7fdcea7de0a0/initial] [perdir /var/www/webtypography.dev/public_html/] applying pattern '^(.*)\\/$' to uri 'toc.php'
[Sat Dec 06 19:04:49.939312 2014] [rewrite:trace1] [pid 5918] mod_rewrite.c(468): [client 192.168.1.100:55227] 192.168.1.100 - - [webtypography.dev/sid#7fdcea80dd68][rid#7fdcea7de0a0/initial] [perdir /var/www/webtypography.dev/public_html/] pass through /var/www/webtypography.dev/public_html/toc.php
These are the only entries in my virtual log for that transaction (i created a separate log for this virtual host...) Also this is NOT a production server, but I am going to look at php.ini and the php error log.... I'm not allowed to comment so I must do this here?
php.ini is display_errors was off!
Now I got the errors I need... THANKS NIEL! Allow me to check these errors, they are simple to fix, how can I give you any credit for this?
If PHP or Apache produces empty output this is nearly always caused by an error in either your Apache configs, including .htaccess files, or in your PHP with display_errors being disabled (as it damn well should be on a production site - you never want to show server internals to a possible attacker).
First stop should be Apache's vhost error logs as they will contain the errors from all these sources.
I'm working on a Drupal site, and the client has requested to prevent any direct access other than the URL aliases defined. That is,
www.clientsite.com -> Allowed
www.clientsite.com/some-internal-page -> Allowed
someclientsite.com/node/add -> Allowed
www.clientsite.com/node -> Denied
www.clientsite.com/node/72 -> Denied
As you can see, I need to disable /node, /node/ and /node/[0-9]* while allowing any /node/some-link-text
I've tried
<LocationMatch ^/node[\/]?([\d]*) >
SetHandler server-status
Order deny,allow
Deny from all
</LocationMatch>
but it doesn't work for /node/add, though all other links work. What regex do I need to fit these conditional matches?
Try this:
RewriteEngine On
RewriteRule ^/node/?$ - [F]
RewriteRule ^/node/[0-9]+$ - [F]
You can write RewriteRul to send 403 as follows.
.htaccess
RewriteEngine On
RewriteRule ^node/?$ - [F]
RewriteRule ^node/[a-zA-Z/]*[0-9]+[a-zA-Z/]*$ - [F]
This will work for,
www.clientsite.com/node/add -> Allowed
www.clientsite.com/node -> Denied
www.clientsite.com/node/72 -> Denied
As well as some extra features you might like,
www.clientsite.com/node/add/another/parameter -> Allowed
www.clientsite.com/node/add/another/72/param/ -> Denied
I am attempting to configure my amazon server with Apache Http to prompt the user for username/password upon hitting the domain via browser.
Here is a snippet from my app.conf file (included in the httpd.conf)
Alias / "/opt/bitnami/apache2/htdocs"
<Directory "/opt/bitnami/apache2/htdocs">
AuthType Basic
AuthName "No Trespassing"
AuthUserFile "/opt/bitnami/apache2/users"
Require valid-user
<IfVersion < 2.3 >
Order allow,deny
Allow from all
Satisfy all
</IfVersion>
<IfVersion >= 2.3>
Require all granted
</IfVersion>
ErrorDocument 403 "Authentication error"
</Directory>
After logging in I am redirected to a 401 "Authorization error" page. Any reason here? I am thinking perhaps my other .conf file causes some conflict.
In httpd.conf I have the following:
WSGIScriptAlias / /opt/bitnami/apps/django/scripts/djangoApp.wsgi
<Directory '/opt/bitnami/apps/django/django_projects/djangoApp'>
Order allow,deny
Allow from all
Satisfy all
</Directory>
Could the first line of each of those snippets be causing a conflict here, preventing me from logging in? I am not sure, but they both look to be creating a similar alias.
If there are any more details I should provide, please let me know.
Here is the error in the logs:
[Wed Jan 09 03:49:49 2013] [error] [client X.X.X.X] client denied by server configuration: /opt/bitnami/apache2/htdocsindex.html
[Wed Jan 09 03:49:49 2013] [error] [client X.X.X.X] client denied by server configuration: /opt/bitnami/apache2/htdocsfavicon.ico
[Wed Jan 09 03:50:28 2013] [error] [client X.X.X.X] client denied by server configuration: /opt/bitnami/apache2/htdocsindex.html
[Wed Jan 09 03:50:28 2013] [error] [client X.X.X.X] client denied by server configuration: /opt/bitnami/apache2/htdocsfavicon.ico
[Wed Jan 09 03:50:28 2013] [error] [client X.X.X.X] client denied by server configuration: /opt/bitnami/apache2/htdocsfavicon.ico
I would try some changes.
First your first Alias / "/opt/bitnami/apache2/htdocs" would easily be replaced by a DocumentRoot /opt/bitnami/apache2/htdocs instruction.
Then you have several Aliases in place, both for "/". Instead of url-filesystem mapping instructions like Alias and AliasMap I would simple use a Location instruction for the security settings.
<Location />
(... Auth basic stuff)
<Location>
By using Location you work on the url and not on the filesystem mapping.
I think your problem is one of 2 things:
potential solution #1
Simply that the user that Apache is running as doesn't have access to the /opt/bitnami/apache2/htdocs directory.
See this page for more details on dealing with the "client denied by server configuration errors": http://wiki.apache.org/httpd/ClientDeniedByServerConfiguration
Check to see what user/groups are set on the /opt/bitnami directory tree. Make sure that they're friendly to the Apache user.
potential solution #2
Also if you look at your error messages the path is missing a '/' after htdocs. See the paths:
/opt/bitnami/apache2/htdocsindex.html
/opt/bitnami/apache2/htdocsfavicon.ico
I think you need to add a trailing slash, '/', to your Alias line like so:
Alias / "/opt/bitnami/apache2/htdocs/"
What am I doing wrong with this regex.
My requested url
http://domain.com/local/v11/full/#Q73Ps/
What I have in .htaccess
Options +FollowSymlinks
RewriteEngine On
RewriteRule ^local/v11/full/#([a-zA-Z0-9]+)/ local/v11/server/full.php?token=$1
The above rule always give me 404 error.
Added Logs
related apache error
[Thu Feb 09 14:04:21 2012] [error] [client 127.0.0.1] File does not exist: /path/to/folder/local/v11/full
related access logs
[09/Feb/2012:14:16:54 +0500] "GET /local/v11/full/ HTTP/1.1" 404 340
no re-write log
when you try to access: http://domain.com/local/v11/full/#Q73Ps/ browser send request for: http://domain.com/local/v11/full/ and doesn't consider #Q73Ps/ as part of URL. if you want to get your rewrite rule working replace # in URL with %23 and it will work.