2010-11-29 5 views
1

La tentative de conversion de mon fichier .htaccess en NGINX. J'ai lu les guides d'aide en ligne, mais je suis toujours en difficulté.Aide pour le fichier .htaccess d'Apache

Quelqu'un voudrait-il m'aider? Mon .htaccess est:

Options -Indexes 
Options +FollowSymLinks 

# Enable ETag 
FileETag none      

# Set expiration header 
ExpiresActive on 
ExpiresDefault A2592000 
Header append Cache-Control "public" 

# Compress some text file types 
AddOutputFilterByType DEFLATE text/html text/plain text/css text/xml application/x-javascript text/javascript application/javascript application/json 

# Deactivate compression for buggy browsers 
BrowserMatch ^Mozilla/4 gzip-only-text/html 
BrowserMatch ^Mozilla/4\.0[678] no-gzip 
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html 

# Set header information for proxies 
Header append Vary User-Agent 

######################################################## 
# Rewrite Rules 
######################################################## 

RewriteEngine on 

# Require SSL (HTTPS) on the signup page 
RewriteCond %{SERVER_PORT} 80 
RewriteCond %{REQUEST_URI} ^/signup/? 
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L] 

# Redirect /signup/plan or /signup/plan/ -> /signup/index.php?account_type=plan 
RewriteRule ^signup/([A-Za-z]+)/?$ /signup/index.php?account_type=$1 [NC,L] 

# Redirect /home/123 or /home/123/ -> home.php?home_id=123 
RewriteRule ^home/([0-9]+)/?$ home.php?home_id=$1 [NC,L] 

# Redirect /homes/ in case someone made a typo when it should have been /home/ 
RewriteRule ^homes/([0-9]+)/?$ home.php?home_id=$1 [NC,L] 

########################################################### 
# Error Handling 
########################################################### 

#ErrorDocument 400/
#ErrorDocument 401/
#ErrorDocument 403/
#ErrorDocument 404/
#ErrorDocument 500/


################################################# 
# Default Settings 
################################################# 

# hide apache server signaute on apache generated pages (e.g. 404) 
ServerSignature Off 

MISE À JOUR:

Pour la compression GZIP, cela semble fonctionner. Mais je n'ai toujours pas compris comment mes règles de réécriture HTTP sont encore.

gzip    on; 
    gzip_min_length 1000; 
    gzip_proxied  expired no-cache no-store private auth; 
    gzip_types  text/plain application/xml; 
    gzip_disable  "MSIE [1-6]\."; 

MISE À JOUR 2

J'ai essayé de remplacer mes règles de réécriture htaccess avec les règles de Nginx suivantes, mais cela ne semble pas fonctionner. Des idées de ce que je fais mal?

# Redirect /signup/planname or /signup/planname/ -> /signup/index.php?account_type=planname 
rewrite ^signup/([A-Za-z]+)/?$ /signup/index.php?account_type=$1 last; 

# Redirect /home/123 or /home/123/ -> home.php?home_id=123 
rewrite ^home/([0-9]+)/?$ home.php?home_id=$1 last; 

# Redirect /homes/ in case someone made a typo when it should have been /home/ 
rewrite ^homes/([0-9]+)/?$ home.php?home_id=$1 last; 

MISE À JOUR 3

par les commentaires ci-dessous, j'ai maintenant la configuration Nginx suivante, mais je suis toujours des problèmes

# gzip 
gzip    on; 
gzip_min_length 1000; 
gzip_proxied  expired no-cache no-store private auth; 
gzip_types  text/plain application/xml; 
gzip_disable  "MSIE [1-6]\."; 


# Require SSL (HTTPS) on the signup page 
# ====== THIS DOESN'T WORK AND BREAKS NGINX 
# I obviously change "example.com" to be my actual domain 
if (location /signup/) { 
    rewrite^https://www.example.com$request_uri? permanent; 
} 


# Redirect /signup/planname or /signup/planname/ -> /signup/index.php?account_type=planname 
rewrite ^signup/([A-Za-z] +)/?$ /signup/index.php?account_type=$1 last; 

# Redirect /home/123 or /home/123/ -> home.php?home_id=123 
# Also, Redirect /homes/ in case someone made a typo when it should have been /home/ 
rewrite ^/homes?/([0-9]+)/?$ /home.php?home_id=$1? last; 

Répondre

0

Comme je vois dans documentation, vos règles (non condes) devrait être comme ceci:

A:

RewriteCond %{SERVER_PORT} 80 
RewriteCond %{REQUEST_URI} ^/signup/? 
RewriteRule ^(.*)$ https://www.example.com/$1 

N (voir here pour plus d'info):

if (location /signup) { 
    rewrite^https://pma.clinicacgm.0$request_uri? permanent; 
} 

A:

RewriteRule ^home/([0-9]+)/?$ home.php?home_id=$1 
RewriteRule ^homes/([0-9]+)/?$ home.php?home_id=$1 

N:

rewrite ^/homes?/([0-9]+)/?$ /home.php?home_id=$1? last; 
+0

Merci Eir. Question cependant, je ne veux que # (chiffres) permet dans la dernière règle. On dirait que vous avez fait la règle pour autoriser n'importe quel type de personnage lorsque vous utilisez "(. *)", Comment puis-je en faire seulement #? –

+0

désolé, je viens de copier à partir du wiki .. Il devrait y avoir '([0-9] +)' ou '([0-9] +)?' (Je n'ai pas de serveur où les tester à peine) –

+0

As tel, aucune idée alors pourquoi mon UPDATE 2 ne fonctionne pas puisque c'est exactement ce que j'ai fait –