Not working nginx rewrite URLs.

  • Posted on September 5, 2015
  • Nginx
  • fkAsked by fk

A custom script I use Apache also working normally. But there are also nginx rewrite error. Do you think this .htaccess file; It should be based on how nginx?

RewriteEngine On
RewriteCond %{HTTP_HOST} ^
RewriteRule (.*)$1 [R=301,L]

ErrorDocument 400 /index.php
ErrorDocument 401 /index.php
ErrorDocument 403 /index.php
ErrorDocument 404 /index.php

<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html text/xml text/css text/plain
AddOutputFilterByType DEFLATE image/svg+xml application/xhtml+xml application/xml
AddOutputFilterByType DEFLATE application/rdf+xml application/rss+xml application/atom+xml
AddOutputFilterByType DEFLATE text/javascript application/javascript application/x-javascript
AddOutputFilterByType DEFLATE application/x-font-ttf application/x-font-otf
AddOutputFilterByType DEFLATE font/truetype font/opentype

<IfModule mod_expires.c>
ExpiresActive On ExpiresByType image/gif "access plus 4 weeks"
ExpiresByType image/jpg "access plus 4 weeks"
ExpiresByType image/jpeg "access plus 4 weeks"
ExpiresByType image/png "access plus 4 weeks"
ExpiresByType image/bmp "access plus 4 weeks"
ExpiresByType text/css "access plus 4 weeks"
ExpiresByType application/javascript "access plus 4 weeks"
ExpiresByType application/x-javascript "access plus 4 weeks"
ExpiresByType text/javascript "access plus 4 weeks"

RewriteRule ^etiket/([0-9a-zA-Z-_]+)/(.*)/$ index.php?do=etiket&tip=$1&link=$2
RewriteRule ^etiket/([0-9a-zA-Z-_]+)/(.*)/s/([0-9]+)(/?)$ index.php?do=etiket&tip=$1&link=$2&s=$3

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([0-9a-zA-Z-_]+)(/?)$ index.php?do=$1
RewriteRule ^([0-9a-zA-Z-_]+)/s/([0-9]+)(/?)$ index.php?do=$1&s=$2
RewriteRule ^([0-9a-zA-Z-_]+)/([0-9]+)/([0-9a-zA-Z-_]+)(/?)$ index.php?do=$1&id=$2&link=$3
RewriteRule ^([0-9a-zA-Z-_]+)/([0-9]+)/([0-9a-zA-Z-_]+)/s/([0-9]+)(/?)$ index.php?do=$1&id=$2&link=$3&s=$4

RewriteRule ^iframe/([0-9a-zA-Z-_]+)(/?)$ lib/iframe.php?tip=$1
RewriteRule ^gazete/([0-9a-zA-Z-_=/]+)(/?)$ lib/gazete.php?url=$1
RewriteRule ^rss/([0-9a-zA-Z-_]+).xml(/?)$ lib/rss.php?tip=$1
RewriteRule ^sitemaps-(.*).xml$ sitemaps.php?goster=sitemap&sayfa=$1 [L]
RewriteRule ^sitemap.xml$ lib/sitemap.php
RewriteRule ^sitemaps.xml$ sitemaps.php
RewriteRule ^yandexfeed.xml$ sitemapsyandex.php

RewriteRule ^GoogleNewsMap/News$ haritalar.php
RewriteRule ^GoogleNewsMap/News/$ haritalar.php
RewriteRule ^GoogleNewsMap/News/([0-9]+)$ harita_yeni.php?basla=$1

RewriteRule ^news_sitemap.xml$ news_sitemap.php

RewriteCond %{HTTP_HOST} ^domain\.com\.tr$ [OR]
RewriteCond %{HTTP_HOST} ^www\.domain\.com\.tr$
RewriteRule ^/?$ "http\:\/\/www\.domain\.com" [R=301,L]

#Change upload limits
php_value memory_limit 512M
php_value post_max_size 512M
php_value upload_max_filesize 512M
php_value max_execution_time 900
#Change upload limits end

<files wp-config.php>
order allow,deny
deny from all
<files wp-load.php>
order allow,deny
deny from all
Options All -Indexes
ServerSignature Off

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

In nginx you shouldn’t use it like this. Its a whole different configuration and in nginx you should use a more efficient config. Alot of people are going in the wrong with this. Check the following conf.:

server {
    listen       80;
    return       301$request_uri;

server {
    listen       80;
    <All The Other Needed Configs>

In nginx, you should seperate the redirecting block and the actual site block. The first block redirects with the 301 to the site link you would like to use. The HTTP response status code 301 Moved Permanently is used for permanent URL redirection, meaning current links or records using the URL that the response is received for, should be updated. The second block will contain the actual config for your website. So you should add the needed code you need in there. Hope this will help you, and please give a report and a like if it works ;)