.htaccess mod_rewrite [P] for https

I have the following code in my .htaccess:

<ifModule mod_rewrite.c>
#RewriteCond %{HTTP_HOST} ^www.example.com
RewriteCond %{REQUEST_URI} !^/social/retrievePage.php 
RewriteRule ^(.*)$ http://www.example.com/social/retrievePage.php?page=%{REQUEST_URI} [P]
</ifModule>

Basically it will remap any page to https://www.example.com/social/retrievePage.php and pass REQUEST_URI as page GET parameter.

It works well, however when I set SSL certificate for my domain, this will not work as expected, instead of remapping it will make a 301 Redirect

I tried fixing the issue by replacing http to https from RewriteRule, got 500 Internal Server Error.

What could be the issue?


Source: stackoverflow-php

Rewrite URL remove part of URl

I need to remove part of a url.

http://whatever.net/api/users/1

I want to redirect this request without api in path to a file located in the same directory named api.php

I have following directory structure

root/api/{here we are}

So I need that my api.php file only receives user/1 in this case

I have tried the following configuration, but it doesn’t work – Not Found

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^api/(.*)$ api.php/$1 [L]
</IfModule>

Please help to get this working


Source: stackoverflow-php

Rewrite URL to hide id

I have the following url on my website:
www.example.com/video?id=468/video-title

I want to rewrite it in htaccess so that it appears as:
www.example.com/video/video-title

What regex do i need to use in this scenario for the proper rewrite?


Source: stackoverflow-php

Transfering mod_rewrite rules from htaccess to nginx

I am trying to convert some already working rewrite rules from .htaccess to nginx.
My application has 2 modes, backend (all calls starting with /admin/*) and frontend, the rest of the calls. Backend requests get routed to admin.php while frontend ones get routed to index.php

This works great in apache but in nginx I can only get the frontend routing to work. The /admin/ requests do call the admin.php file but the php file is downloaded instead of being executed. I’ve already used http://winginx.com to convert my htaccess routes to nginx but I still can’t get it to work for /admin.

Can an nginx pro help me out with the proper config to do this?

This is my working .htaccess config:

<IfModule mod_rewrite.c>
#RewriteBase /

# Google sitemap.xml configuration
RewriteRule sitemap.xml$ /index.php?_extension=Frontend&_controller=Sitemap&action=googleSitemap [L,R=301]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+).(d+).(php|js|css|png|jpg|gif|gzip)$ $1.$3 [L]

# admin routes
RewriteRule ^/admin/(.*)$ admin.php?%{QUERY_STRING} [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l

# frontend routes
RewriteRule .* index.php [L]

</IfModule>

and this is the nginx configuration that I tried so far…

server {
    listen       80;
    server_name  mydomain.local;
    root   /var/www/project;
    index  index.php index.html index.htm;
    access_log  /var/log/nginx/default-access.log  main;
    error_log   /var/log/nginx/default-error.log;

    error_page   500 502 503 504  /50x.html;

    location = /50x.html {
        root   /var/www/default;
    }

    location / {
        rewrite sitemap.xml$ /index.php?_extension=Frontend&_controller=Sitemap&action=googleSitemap redirect;
        try_files $uri $uri/ @rewrite;
    }
    location @rewrite {
        rewrite ^(.*)$ /index.php;
    }
    location /admin {
        rewrite ^/admin/(.*)$ /admin.php?$query_string break;
    }

    location ~ .php {
        include                  fastcgi_params;
        fastcgi_keep_conn on;
        fastcgi_index            index.php;
        fastcgi_split_path_info  ^(.+.php)(/.+)$;
        fastcgi_param PATH_INFO $fastcgi_path_info;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_intercept_errors on;
        fastcgi_pass unix:/var/run/php-fpm.sock;
    }
}

with nginx on, doing a curl -s -D – ‘http://mydomain.local/frontend/call‘ | head -n 20 does return the Content-type as text/html while a call to curl -s -D – ‘http://cms.dev/admin/whatever‘ | head -n 20 returns the application/octet-stream content type which triggers the download.


Source: stackoverflow-php