.htaccess

HTTP authentication logout via PHP

What is the correct way to log out of HTTP authentication protected folder? There are workarounds that can achieve this, but they are potentially dangerous because they can be buggy or don't work in certain situations / browsers. That is why I am looking for correct and clean solution. ...

mod_rewrite, .htaccess connecting to mysql database

I would like mod_rewrite in an .htaccess file to link to a mysql database to provide me with mapping information. Specifically, I am using a single code base to host multiple sites so..if a user requests an image, for example: http://www.example.com/images/car.jpg this is going to hit my server and many other sites will also be hitting...

apache resolving urls before looking in .htaccess

I have a rewrite rule of the following form: RewriteRule ^foo/([a-zA-Z0-9]+)$ foo.php?arg=$1 [qsa,nc] It takes urls of the form /foo/bar and changes them to /foo.php?arg=bar It works properly locally, and it works on my old host but I moved to a new host (running ubuntu) and it behaves differently. On the new host apache notices that...

RegEx match replace help

I am trying to do a regex match and replace for an .htaccess file but I can't quite figure out the replace bit. I think I have the match part right, but maybe someone can help. I have this url- http://www.foo.com/MountainCommunities/Lifestyles/5/VacationHomeRentals.aspx And I'm trying to turn it into this- http://www.foo.com/mountain-l...

My site was hacked, htaccess file compromised, what should it look like?

A website I maintain pro-bono was hacked, dishing out 302s to gaming sites, etc. www.rebekahshouse.org. After much searching through my hosting company's control panel, I found the culprit in the htaccess file. It looked something like this: RewriteEngine on RewriteCond %{HTTP_REFERER} .oogle.com [NC,OR] RewriteCond %{HTTP_R...

Rewrite fails to catch simple errors.

Recently I've added the tail of this file to optimize url's like site/5/john-doe[.php] instead of site/5/john-doe/[index.php], however, I rather like my custom error documents, and these modifications call a black & white "Internal Server Error" and "additional 404" error page. It might be helpful to know that most of the site will rema...

mod_rewrite generating errors in log

On my site I have mod_rewrite rules to make the URLs more search engine friendly, and it all works fine on the frontend, but I'm getting errors in the error log like this [Thu Jan 22 22:51:36 2009] [error] [client {IP ADDRESS HERE}] File does not exist: /{some rewritten directory} The rules I'm using are rather simple, along the lines...

Why does RewriteRule ^page/?$ page.php [L] match site.com/page//

RewriteEngine on RewriteRule ^page/?$ page.php [L] This ends up matching the url www.site.com/page// but internally it acts differently than www.site.com/page/ because the stylesheets and images no longer appear properly. Am I doing something wrong or is this just something I need to deal with if I don't want to go through a lot of tro...

Trouble with encoding special chars for URL through text input

So I'm building a simple php application using CodeIgniter that is similar to Let Me Google That For You where you write a sentence into a text input box, click submit, and you are taken to a URL that displays the result. I wanted the URL to be human-editable and relatively simple so I've gotten around the CodeIgniter URL routing a bit. ...

htaccess mod_deflate does not work on shared server

Hello. I'm developing a website in PHP and I have large JS files that I want to compress. So, I added this in my .htaccess file: <FilesMatch "\.(js|css|html|htm|php|xml)$"> SetOutputFilter DEFLATE </FilesMatch> It works great on my local wamp server install but once I move the files on my shared server, the DEFLATE command does n...

.htaccess isn't handling root of the folder properly

So I have this .htaccess file in the /blog/ folder on my webserver and to work with the blog CMS we are using for this particular client (Expression Engine) I wrote this .htaccess to make the URLs SEO friendly. It all works great unless I go to www.example.com/blog/ then it goes through to the bottom rule which I don't want it to. I ...

.htaccess - rewriting and then hiding part of the url?

I have the following RewriteRule in my .htaccess: RewriteRule ^products/([A-Za-z0-9-\s\@]+)/([A-Za-z0-9-\s\@]+)/?$ /store/products/product.php?prod=$1&src=$2 [L,QSA] It takes a url such as: http://photojojo.com/store/products/lawnmower/blogThatLovesUs and shows the page here: http://photojojo.com/store/products/product.php?prod=lawnm...

Apache alternatives to PHP header function.

I'm working on a website that has a number of style sheets all of which need to be handled as php scripts server-side. My .htaccess file looks something like this: <FilesMatch "\.(css)$"> ForceType application/x-httpd-php </FilesMatch> This causes a small problem as the mime type of the http-response's Content-Type field is then s...

.htaccess at any length

What would be the valid .htaccess rules for doing something like this /mypage/ --> /index.php?page=mypage /mypage/param1/value1/ -->index.php?page=mypage&params=param1/value1 With an potentially unlimited number of parameters? Thanks. ...

.htaccess ordering?

What's the most efficient and logical way to order sections of a .htaccess file? ...

Query Strings & Mod ReWrite

Hey there, I'm not too inexperienced with ReWrite (not a master either, though) so I was hoping somone might be able to help me. RewriteRule ^$ index.php?page=home [NC] RewriteRule ^adm$ index.php?page=adm_home [NC] RewriteRule ^adm/stats index.php?page=adm_stats [NC] Above is a snippet of my .htaccess file. As you can see, when so...

How would I require a password for all files except one using .htaccess?

I have a new website I'm working on that the client wants to keep a secret, but at the same time, I want to put an under construction page with some info on it. I would like to have everything except index.html require a user/password--index.html would be available to everyone. I have the following, but I'm not sure what I need to add: ...

.htaccess Redirects

How do I set up an .htaccess file to redirect requests to another folder on another domain? I don't want the links to break, I just want them to go elsewhere. Say mysite.com/image.jpg would redirect to site2.com/images/image.jpg. ...

Clean URL Redirect Loop

Hello! I'm trying to create clean URLs on my website. Now I succeeded in configuring apache so every request like mysite.com/page will work. But I also want that requests for mysite.com/page.php will be redirected to mysite.com/page. I've set environment variable in .htaccess to check if i already been redirected to prevent loops, but i ...

With Django, what's the correct way to set up paths to the admin content and static content?

I have a Django site set up that uses the Django admin panel, prefixed with /media/, as well as static site content in a directory called /static/. The admin media stuff, of course, lives within the Django package, and the site's static content is stored along with the Python code for the site. Currently, my public_html just contains ap...