I'm not good at English.
I use Ubuntu10.04(ja).
I installed pukiwiki(wiki) in /var/www/mypukiwiki. I want to access this page like "http://XX.XX.XX.XX" and redirect "http://XX.XX.XX.XX/pukiwiki" and "http://XX.XX.XX.XX/pukiwiki/" to "http://XX.XX.XX.XX". So, I modified my default configuration file below.
DocumentRoot /var/www/mypukiwiki
RewriteEngine on
RewriteRule /pukiwiki/(.*) /$1 [R]
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/mypukiwiki>
Options Indexes FollowSymLinks MultiViews
#AllowOverride None
AllowOverride All
Order allow,deny
allow from all
</Directory>
But, Apache redirect only "http://XX.XX.XX.XX/pukiwiki/" to "http://XX.XX.XX.XX".
Apache cannot redirect "http://XX.XX.XX.XX/pukiwiki/" to "http://XX.XX.XX.XX".
Why? I want to know correct configuration.
Would you help me?
Change:
RewriteRule /pukiwiki/(.*) /$1 [R]
to:
RewriteRule ^/pukiwiki/?(.*) /$1 [R,L]
The ^ in the beginning of the match is to ensure you're matching from the beginning of the path, and not match against something like "/foo/bar/pukiwiki", the ? after the slash indicates that it's optional.
Related
How do i rewrite static files request like
http://example.com/assets/img/logo.png
to
http://assets.example.com/img/logo.png
main site rewrite rules
ServerName example.com
ServerAlias example.com
DocumentRoot /var/www/html/example.com/public/
<Directory /var/www/html/example.com/public/ >
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
RewriteEngine on
RewriteCond %{HTTP_HOST} !assets\.site\.com
RewriteCond %{REQUEST_URI} \.(png|gif|ico|css|js|tiff|woff|woff2|ogg|mp3)$ [NC]
RewriteRule ^(.*) http://assets.example.com$1 [NC,L]
sub-domain for assets is working properly
virtual host config for assets.example.com
ServerName assets.example.com
ServerAlias assets.example.com
DocumentRoot /var/www/html/example.com/public/assets/
<Directory /var/www/html/example.com/public/assets/ >
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
http://assets.example.com/img/logo.png gives a 404
but if i create a /var/www/html/example.com/public/assets/assets/ then http://assets.example.com/img/logo.png reutns 200
Per your comment, you just need to change the what you're capturing in the regex used by the RewriteRule. Right now $1 is the value of what's in (.*). You can remove "assets" from that by adding it to the path prior to your capture group.
Change:
RewriteRule ^(.*) http://assets.example.com$1 [NC,L]
To:
RewriteRule ^assets/(.*) http://assets.example.com/$1 [NC,L]
It looks like Apache Rewrite Rules are ignoring the '#' in the Request URI.
I want to rewrite the following Request
hptt://localhost/app_name/#Place=abc
to
http://localhost/app_name/#/#ID=abc
And here are the Rules i have tried so far and none of them worked.
RewriteEngine on
# Rule 1
RewriteCond %{HTTP_REFERER} %{HTTP_HOST}/app_name/#Place=(.*)$ [NC]
RewriteRule ^app_name/#Place=(.*)$ /app_name/#/#ID=$1 [R,L]
# Rule 2
RewriteCond %{QUERY_STRING} ^#Place=(.*)$ [NC]
RewriteRule ^app_name/#Place=(.*)$ /app_name/#/#ID=$1 [R,L]
When i tried Rule 1) at http://martinmelin.se/rewrite-rule-tester/ it is working as expected. How ever my local apache is not rewriting the rule
Thanks
Maybe the apache not allowed overwrite rules with .htaccess.
in case you are on ubuntu edit the file /etc/apache2/apache2.conf
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
and change it to
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
then restart apache
sudo service apache2 restart
Fragments are not sent in the HTTP Request Messages by web browser. It's pointless to try work with them in an server side.
I am making a test with codeigniter and I make this .htaccess:
#Options +FollowSymLinks
#Options -Indexes
DirectoryIndex index.html index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|css|Scripts|images|uploads)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
On the config files of apache where is necessary make many changes, I have this (only what I think is important for this case):
/etc/apache2/apache2.conf
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
/etc/apache2/site-available/000-default.conf
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html
<Directory />
#Options FollowSymLinks
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order deny,allow
Allow from all
</Directory>
The path where the codeigniter is installed is in /var/www/html/test, and if on browser I make http://ejemplo.com/test the wellcome controller of igniter works, but if I try to access to other function on this controller I get a 404 (make by apache, not the 404 from codeigniter).
Do I forget something?? What am I doing wrong??
Thank you.
PS:The codeigniter is an empty and new installation (only a helloworld function on the wellcome controller).
I am trying to redirect the index.php to /, at the Document root: /var/www/ by configuring the /etc/apache2/sites-enabled/000-default file.
Using Ubuntu 14.04 Server with apache2.
These are the contents of the Directory directive at /etc/apache2/sites-available/000-default:
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Require all granted
This is what I've tried from another question here:
<Directory "/var/www">
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Require all granted
RewriteCond %{THE_REQUEST} ^/index.php$
RewriteRule $(.*)^ / [R=301,L]
</Directory>
I've even tried this RewriteRule ^(.*)index\.(php|html?)$ /$1 [R=301,NC,L], and also RedirectMatch 301 ^/index.php$ http://www.example.com (this time I removed, the RewriteCond).
What happens
I can normally access my site from /, but when I add /index.php I get redirected to wwww.mydomain.com (notice the 4 ws).
What am I doing wrong?
I am working with the built-in Apache2 on OSX. I moved the document root to a folder on my desktop and made sure that _www and everyone have read access. It works fine and great, PHP works, everything works until I add a .htaccess with this line only:
RewriteEngine on
As soon as I do that, everything in the directory with the file is 403 Forbidden:
Forbidden
You don't have permission to access /dir/file.txt on this server.
Apache logs show this error:
[error] [client 127.0.0.1] Options FollowSymLinks or SymLinksIfOwnerMatch is off which implies that RewriteRule directive is forbidden: /Users/uname/Desktop/localhost/dir/filename.txt
I've gone through httpd.conf and made sure that I've enabled FollowSymLinks to no avail:
DocumentRoot "/Users/uname/Desktop/localhost"
<Directory />
Options FollowSymLinks
Options SymLinksIfOwnerMatch
AllowOverride All
Order allow,deny
Allow from all
</Directory>
<Directory "/Users/uname/Desktop/localhost">
Options FollowSymLinks
Options SymLinksIfOwnerMatch
Options Indexes MultiViews
AllowOverride All
Order allow,deny
Allow from all
</Directory>
If I comment out RewriteEngine on in the .htaccess file, then everything works fine, except rewrite rules, obviously. On OSX 10.8.5, httpd.conf is located in /etc/apache2 which also has the folder users containing individual files for uses, e.g. uname.conf, but I've added symlinks in here same as in the other. I noticed there's also a folder extra with files like httpd-userdir.conf, but they don't seem to disable anything.
Where else can FollowSymLinks be turned on (or off)?
You have to either put your Options on one line, or add a + sign in front of your Options so Apache understands you want merge them. At the moment only the last Options directive ('Options Indexes MultiViews') is being applied since it is overwriting all the prior Options.
Try this (which will overwrite the '/' Options):
<Directory "/Users/uname/Desktop/localhost">
Options Indexes MultiViews FollowSymLinks SymLinksIfOwnerMatch
AllowOverride All
Order allow,deny
Allow from all
</Directory>
I had an issue with getting a 403 the solution for me was changing my rewrite rules. My complete directives are as follows:
<Directory "/var/www/">
<LimitExcept GET POST HEAD>
Order Allow,Deny
Deny from all
Satisfy all
</LimitExcept>
Require all granted
AllowOverride None
# Disable includes and cgi
Options -Includes
Options -ExecCGI
<IfModule mod_rewrite.c>
RewriteEngine On
# Redirdect to HTTPS
RewriteCond %{HTTP_HOST} ^example.com
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
RewriteCond %{HTTP_USER_AGENT} ^$
RewriteRule ^(.*)$ - [F,L]
# Put your installation directory here:
RewriteBase /
# Do not enable rewriting for files or directories that exist
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# remove index.php
RewriteRule ^(.*)$ /index.php/$1 [L]
# If your host requires forcing query strings.
# Notice the question at the end of index.php
# on the last rule
#RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_FILENAME} !-d
#RewriteRule ^(.*)$ /index.php?/$1 [L]
</IfModule>
</Directory>
ServerName www.example.com
ServerAlias www.example.com