yyt_sjq
yyt_sjq

Reputation: 11

Help Converting Apache htaccess to Nginx Rewrite rules

I need to convertthe following Apache htaccess rules to Nginx Rewrite rules:

Redirect 301 /feed.php http://www.example.com/feed/

Thanks very much~

Upvotes: 1

Views: 2400

Answers (2)

Janne
Janne

Reputation: 113

Use the following bash one-liner, to convert Apache Redirect lines in the .htaccess file:

while read LINE; do echo -e `echo $LINE | egrep '^Redirect' | cut -d' ' -f1-2` "{\n\treturn 301 `echo $LINE|cut -d' ' -f3`;\n}"; done < .htaccess

As a result,

Redirect /feed.php http://www.example.com/feed/

... lines are printed to the following Nginx style:

location /feed.php {
         return 301 http://www.example.com/feed/;
}

Upvotes: 1

pjmorse
pjmorse

Reputation: 9294

Formatting's a bit off, but I assume your original rule was

Redirect 301 /feed.php http://www.example.com/feed/

so the Nginx rewrite would be

rewrite ^/feed\.php http://www.example.com/feed/ permanent;

Not difficult if you read the documentation.

Upvotes: 3

Related Questions