mod-rewrite

How do I convert mod_rewrite (QSA option) to Nginx equivalent?

I'm looking to convert the following mod_rewrite rule to the Nginx equivalent: RewriteRule ^foo/(.*)$ /bar/index.php?title=$1 [PT,L,QSA] RewriteRule ^foo/*$ /bar/index.php [L,QSA] So far I have: rewrite ^foo/(.*)$ /bar/index.php?title=$1&$query_string last; rewrite ^foo/?$ /bar/index.php?$query_string break; The problem is (I think...

How do I use HTTP Authentication for a specific URL (not a directory)

I have an htaccess file that uses mod_rewrite to redirect /controller to /index.php?controller=%controller% Like this: # Various rewrite rules. <IfModule mod_rewrite.c> RewriteEngine on # Rewrite current-style URLs of the form 'index.php?controller=x&action=y'. RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME...

Apache Mod Rewrite (.htaccess)

Given my current .htaccess file, how would I modify it to check for an additional URL path like '/src/pub/' and rewrite it to '/' without affecting the current rewrite? Here's the original .htaccess file: RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php?route=$1 [L,...

Hidden features of mod_rewrite

There seem to be a decent number of mod_rewrite threads floating around lately with a bit of confusion over how certain aspects of it work. As a result I've compiled a few notes on common functionality, and perhaps a few annoying nuances. What other features / common issues have you run across using mod_rewrite? ...

Apache Redirect Rule Always fires on every request

So the following rewrite rules always seem to fire. This has the effect of hiding another domain that I am hosting on the server? I can't seem to figure out what's wrong and it is time to call in the experts: RewriteEngine on RewriteCond %{HTTP_HOST} ^danielhonig.com RewriteRule ^(.*)$ http://www.danielhonig.com/$1 [R=permanent,L] Re...

Mod-rewrite shenanigans...

I have this rewrite rule RewriteEngine On RewriteBase /location/ RewriteRule ^(.+)/?$ index.php?franchise=$1 Which is suppose to change this URL http://example.com/location/kings-lynn Into this one http://example.com/location/index.php?franchise=kings-lynn But instead I am getting this http://example.com/location/index.php?fran...

Mod-rewrite Trailing Slash Issue

There doesn't seem to be much info on this topic so I'm going to outline my specific problem then maybe we can shape the question and the answer into something a bit more universal. I have this rewrite rule RewriteEngine On RewriteBase /bookkeepers/ RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(....

How do I redirect URLS that begin with /test/ to a separate script?

I have an existing htaccess that works fine: RewriteEngine On RewriteCond %{SCRIPT_FILENAME} !-f RewriteCond %{SCRIPT_FILENAME} !-d RewriteRule (.*) /default.php DirectoryIndex index.php /default.php I wish to modify this so that all urls that start with /test/ go to /test/default.php. Example: http://www.x.com/hello.php -- > http:/...

Htaccess Two different redirects.

I have an existing htaccess that works fine: RewriteEngine On RewriteCond %{SCRIPT_FILENAME} !-f RewriteCond %{SCRIPT_FILENAME} !-d RewriteRule (.*) /default.php DirectoryIndex index.php /default.php I wish to modify this so that all urls that start with /test/ go to /test/default.php, while keeping all other URLs with the existing /...

RewriteRule redirect

Okay I have this RewriteRule which is supposed to redirect any request for the file base.css to {folder of .htacces file}/include/style/base.css, but is just keeps redirecting in an infinite loop, I thought the L parameter would make sure that wouldn't happen. RewriteRule (.*)/base.css$ include/style/base.css [L,NC,R=301] Also it redi...

URL Rewrite blanket redirect with directory exceptions

I have a website that employs a generic mod_rewrite rule to push all requests to the index.php page, with the exception of certain file extensions: RewriteRule !\.(js|ico|gif|jpg|JPG|png|css|php|phtml|pdf|txt|xml)$ index.php What I need to be able to do is also exclude a certain directory (including any files or sub-directories contai...

How to use apache mod_rewrite and alias at the same time?

I have a directory outside the webroot that is used for storing images uploaded from a separate admin system. Images are stored in this format: filepath/writable/images/00/00/23/65/filename-236581.jpg (where the webroot is filepath/html) ...for example. Here, 236 is the ID of the image in the database, and the file system is broken in...

Redirect joomla url's to wordpress

Hi. I moved an ex-site based on joomla to wordpress. Import worked fine but the problem is that the old links don't work anymore. Because there is only 50 or so articles, i thought will be a good idea to put a rule for each post (in .htaccess). Well... Not always things are like you want, so redirects dont work at all :( Old joomla lin...

Mod Rewrite rule to Zeus Server rule (Codeigniter)

Hi everyone, I'm about to go live with a Codeigniter powered site. I want to remove index.php from the url so that instead of this: http://www.mysite.com/index.php/controller I get something like this: http://www.mysite.com/controller So far, pretty straightforward. In the past I've used the mod-rewrite rule supplied by the Codeig...

Using mod_rewrite in .htaccess in both website root and a subdirectory

My dilema: In .htaccess in my website's root: RewriteEngine On RewriteCond %{HTTP_HOST} !^www\.example\.com [NC] RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L] In .htaccess in the subdirectory /foo RewriteEngine On RewriteRule ^page1\.html$ /foo/page2.html [R=301] In the first, I'm trying to ensure all requests include the...

How can I implement a global RewriteCond / RewriteRule in Apache that applies to all virtual hosts?

The title pretty much says it all. :-) I have lots of virtual hosts and I want to put a single rewriting block at the top of the httpd.conf file that rewrites URLs no matter which virtual host the request might be directed to. How the heck do I do this? I found this but my question is the same: how can I do this without resorting to ...

How do I rewrite this RewriteRule?

I have this rewrite rule RewriteRule (.*)/([^/\.]+).css$ include/style/styleRedir.php?css=$2.css [L,NC] which matches thing like: somefolder/foo.css and rewirites them to: include/style/styleRedir.php?css=foo.css however it won't match: foo.css So I tried changing it to: RewriteRule (.*)(/?)([^/\.]+).css$ include/styl...

301 redirect

How do i redirect a url to domain . eg. http://www.mydomain.com/index.php=HairThing --> http://www.mydomain.com How do i redirect a non-www to www WITHOUT a slash at end ? eg http://mydomain.com ---> http://www.mydomain.com ...

How do you restrict access to certain paths using Lighttpd?

I would like to restrict access to my /admin URL to internal IP addresses only. Anyone on the open Internet should not be able to login to my web site. Since I'm using Lighttpd my first thought was to use mod_rewrite to redirect any outside request for the /admin URL back to my home page, but I don't know much about Lighty and the docs...

What do you think about this weird idea about how to configure development/staging/production instances?

I just got a weird idea about how to configure environment-dependent parameters. Sort of like parameters you can find in Rails' config/database.yml In my current project I use PHP and Litespeed Web Server (though the same technique applies to PHP + Apache), and I thought... 'why not use mod_rewrite for this?'. I have separate virtual ho...