I read this and here I am trying to do a 302 redirect using apache. I'm using the default Apache shipped with OSX 10.7:
Server version: Apache/2.2.21 (Unix)
Server built: Nov 15 2011 15:12:57
I tried to:
Create an .htaccess file and place inside:
Redirect temp /old.html http://localhost/new.html
or
Redirect 302 /old.html http://localhost/new.html
or
Redirect /old.html http://localhost/new.html
In httpd.conf modify the following section (note that in the conf file I see also LoadModule alias_module libexec/apache2/mod_alias.so):
<IfModule alias_module>
Redirect /old.html http://localhost/new.html
</IfModule>
I stopped/started several times Apache but with no luck. What's wrong?
Thanks!
EDIT: By not working I mean I get a 404!
Using Redirect directive requires that mod_alias is loaded.
Using Redirect directive inside .htaccess requires that at least FileInfo can be overridden. You need to add AllowOverride FileInfo in the appropriate section in httpd.conf (there could be more than one).
When you make changes to httpd.conf you need to restart Apache. This is probably the main issue.
Find the following line in your httpd.conf and change it, from
AllowOverride None
To
AllowOverride All
Related
There are some PHP files on an external drive which is mapped to the Z: drive on a Windows 10 machine. This code is in the httpd-vhosts.conf Apache file:
<VirtualHost *:8080>
DocumentRoot "Z:/files/xampp/htdocs"
<Directory "Z:/files/xampp/htdocs">
Options Indexes
Require all granted
</Directory>
</VirtualHost>
The task at hand is to allow .htaccess overrides for a file path within the path shown above. In the httpd.conf file the rewrite module is enabled. That line looks like this: LoadModule rewrite_module modules/mod_rewrite.so. I tried adding this code to the httpd.conf file:
<Directory "Z:/files/xampp/htdocs/miscellaneous/WebServiceExamples">
AllowOverride All
</Directory>
The Apache web server was stopped and restarted after making these changes. The code in .htaccess looks like this:
<IfModule mod_rewrite.c>
# turn rewrite engine on
Options +FollowSymlinks
RewriteEngine on
# map neat URL to internal URL
RewriteRule ^mobile/list/$ RestController.php?view=all [nc,qsa]
RewriteRule ^mobile/show/([0-9]+)/$ RestController.php?view=single&id=$1 [nc,qsa]
</IfModule>
However, when a URL that should be handled by the rewrite rule in the .htaccess file is entered in the Chrome address bar the result is an Object not found! Error 404. Where did I go astray?
EDIT:
Another thing I tried was putting httpd.conf back to its original state, then modifying httpd-vhosts.conf as follows:
<VirtualHost *:8080>
DocumentRoot "Z:/files/xampp/htdocs"
<Directory "Z:/files/xampp/htdocs">
Options Indexes
Require all granted
</Directory>
<Directory "Z:/files/xampp/htdocs/miscellaneous/WebServiceExamples">
AllowOverride All
</Directory>
</VirtualHost>
After stopping and restarting the Apache web server, the result is still the same as before:
Object not found! Error 404.
Figured this out. The configuration files were left in the state as described in the Edit section in the original post. The Troubleshooting section in this link was a helpful guide for determining that the configuration files were set up correctly.
This was entered as the URL in Chrome's address bar: http://localhost:8080/miscellaneous/WebServiceExamples/SimpleRestfulWebService/mobile/list. Notice there is no trailing forward slash. The rewrite rule was in .htaccess was written in such a way that made a trailing forward slash mandatory. When the rewrite rule lines were modified to make the trailing slash optional, then it worked fine. Here are the modified rewrite rules:
RewriteRule ^mobile/list/?$ RestController.php?view=all [nc,qsa]
RewriteRule ^mobile/show/([0-9]+)/?$ RestController.php?view=single&id=$1 [nc,qsa]
I have images in
/home/crawler/scrapers/images/website
for example
/home/crawler/scrapers/images/website/1/img-name.jpg
My Apache root is at
/var/www/html
I have .htaccess in this folder with following content
RewriteEngine On
RewriteRule ^/images/(.*)$ /home/crawler/scrapers/images/$1 [R,L]
My goal is to show images from the images folder as I mentioned above.
http://website.com/images/website/1/img-name.jpg >> /home/crawler/scrapers/images/website/1/img-name.jpg
Currently I am getting
Not Found
The requested URL /home/crawler/scrapers/images/website/1/img-name.jpg was not found on this server.
Apache/2.4.18 (Ubuntu) Server at IP Port 80
PS: I confirm that hataccess is enabled.
You can use Alias directive for this.
Include following code in your vhosts.conf or httpd.conf and restart Apache.
Alias /images /home/crawler/scrapers/images
<Directory /home/crawler/scrapers/images>
Allow from all
</Directory>
I was playing around with .htaccess files and I was wondering, completely out of curiosity, is it possible to redirect access to the .htaccess file itself to another file?
Example:
User goes to http://www.example.com/.htaccess
I want the user to be redirected to index.php?foo=bar
I've tried the following:
Redirect 301 /.htaccess /index.php?foo=bar
And
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^((?s).*)$ index.php?foo=bar [QSA,L]
</IfModule>
These methods work on any other file, but the .htaccess file itself always results in a 403 Forbidden page showing up.
Is this possible? If not, then why?
If you look in your webservers configuration file you will find some directive that prevents users from accessing .htaccess or .htpasswd file from the browser. For instance if I open up my apache configuration, located at /etc/apache2/apache.conf I can spot the following lines:
#
# The following lines prevent .htaccess and .htpasswd files from being
# viewed by Web clients.
#
<FilesMatch "^\.ht">
Require all denied
</FilesMatch>
So you should be able to change the above to:
Order allow,deny
Allow from all
you also need to make sure that you have the correct file permission on the .htaccess file and finally restart your server using:
sudo service apache2 restart
Of course doing the above would not be very secure.
In my httpd.conf file of my apache server(on windows7), I used LoadModule alias_module modules/mod_alias.so
And then I modified the httpd.conf with the following:
<IfModule alias_module>
Alias /b /blog
ScriptAlias /cgi-bin/ "cgi-bin/"
</IfModule>
After I restarted the server and type the localhost/b in my address bar,however,it did not redirect to the localhost/blog.I don't konw why.Can you help me, Any help is greatly appreciated
Alias declarations aren't the same as redirects.
Alias /b /blog
tells Apache to make the files that exist on your file system under the path /blog (which doesn't mean much on Windows) available at the URL http://myserver.com/b, i.e. a request for http://myserver.com/b/something.html will try to return the content of the file /blog/something.html from your filesystem, failing if that file does not exist - the browser address bar will still say http://myserver.com/b/something.html.
It sounds like what you're after is
Redirect /b http://myserver.com/blog
In this case, a request for http://myserver.com/b/something.html will result in an HTTP redirect, the browser's address bar will change to say http://myserver.com/blog/something.html.
Of course, you then need to ensure that /blog resolves appropriately, which may require its own Alias if it's not under the DocumentRoot.
Alias /blog "C:/web/blog"
<Directory "C:/web/blog">
Order allow,deny
Allow from all
</Directory>
I am trying to rewrite URLs using mod_rewrite. It is enabled in httpd.conf and url rewriting works if the lines are in the httpd.conf file. However, I would like the rules to be in the .htaccess file.
It doesn't appear that .htaccess is being processed at all by Apache on Win2k.
I have ReWriteLogging turned all the way up, but the log file isn't being created. The last line in httpd.conf is
AccessFileName .htaccess
.htaccess contents
RewriteEngine on
RewriteLog "c:/rewrite.log"
RewriteLogLevel 15
RewriteRule /alice.html$ /bob.html
Thanks
edit : Apache version 2.2 on Windows 2k
Check that AllowOverride FileInfo is enabled in httpd.conf for the directories affected; see also http://httpd.apache.org/docs/2.2/mod/core.html#allowoverride. You might also check permissions on the .htaccess files themselves, to ensure there's nothing preventing Apache from reading them.