Stacey is a lightweight content management system. I am using it on my porfolio website however it uses .htaccess file to make friendly urls. Is it possible to rewrite this .htaccess lines for using in nginx? Here is the .htaccess file content;
RewriteEngine on
# Some hosts require a rewritebase rule, if so, uncomment the RewriteBase line below. If you are running from a subdirectory, your rewritebase should match the name of the path to where stacey is stored.
# ie. if in a folder named 'stacey', RewriteBase /stacey
#RewriteBase /
ErrorDocument 404 /404.html
# Rewrite any calls to *.html, *.json, *.xml, *.atom, *.rss, *.rdf or *.txt if a folder matching * exists
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !public/
RewriteCond %{DOCUMENT_ROOT}/public/$1.$2 !-f
RewriteRule (.+)\.(html|json|xml|atom|rss|rdf|txt)$ $1/ [L]
# Add a trailing slash to directories
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(\.|\?)
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ([^/]+)$ $1/ [L]
# Rewrite any calls to /render to the image parser
RewriteCond %{REQUEST_URI} render/
RewriteRule ^render/. app/parsers/slir/ [L]
# Rewrite any calls to /* or /app to the index.php file
RewriteCond %{REQUEST_URI} /app/$
RewriteRule ^app/ index.php [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ index.php?/$1/ [L,QSA]
# Rewrite any file calls to the public directory
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !public/
RewriteRule ^(.+)$ public/$1 [L]`
Thanks in advance!
I achieved some progress. Here it is;
location / {
if ($uri ~ "/app/$"){
rewrite ^/app/ /index.php last;
}
if (!-e $request_filename){
rewrite ^/(.*)/$ /index.php?$1 last;
}
if (!-f $request_filename) {
rewrite ^/(?!public/)(.+);
}
if (!-f $request_filename) {
rewrite ^/(?!public/)(.+)\.(html|json|xml|atom|rss|rdf|txt)$ $1/ last;
}
if (!-e $request_filename) {
rewrite ^/(?!public/)(.+)$ public/$1 last;
}
This rewrite all the projects without any problem right now. For example;
domain.com/?/projects/project-name-3/ became domain.com/projects/project-name-3/
but there is also another 2 pages. one of is "about" and one of is "contact me" . they also became; domain.com/about and domain.com/contact-me but when i click them the page loads but without css styling. any clue?
okay new code is like this and it gives me error; nginx: [emerg] invalid number of arguments in "rewrite" directive in /etc/nginx/sites-enabled/domain.com:21
location / {
rewrite ^/app/ /index.php last;
}
if (!-e $request_filename){
rewrite ^/(.*)/$ /index.php?$1 last;
}
if (!-f $request_filename) {
rewrite ^/(?!public/)(.+);
}
if (!-f $request_filename) {
rewrite ^/(?!public/)(.+)\.(html|json|xml|atom|rss|rdf|txt)$ $2/ last;
}
try_files /public$uri /public$uri/ $uri $uri/ /index.php;
}
the code in the 21. lines are;
rewrite ^/(?!public/)(.+);