简体   繁体   中英

Server Errors with .htaccess mod_rewrite

On my localhost, there is no problem, but when I upload my .htaccess file to my 1and1 hosting account I hit a brick wall (an internal 500 server error)

Update: I found the offending code, just don't know why its broken or how to fix it (I commented out the broken line)

 #RewriteRule ^([a-zA-Z_\-/]+)(\/?)$ index.php?p=$1 [R,NC,QSA,L]
  RewriteRule ^([a-zA-Z_/]+)(\/?)$ index.php?p=$1 [R,NC,QSA,L]

.htaccess file contents:

AddType x-mapp-php5 .php   
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !\.(jpg|jpeg|gif|png|css|js|pl|txt)$
RewriteRule ^([a-zA-Z_\-/]+)(\/?)$ /index.php?p=$1 [L]

Commenting out the final line (RewriteRule...) stops the error from happening but I obviously need this to function.

The file works fine for me on my local machine. Well its a little different so I'll include that code too (differences: flags, '/NEP', and the 1st line)

RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !\.(jpg|jpeg|gif|png|css|js|pl|txt)$
RewriteRule ^([a-zA-Z_\-/]+)(\/?)$ /NEP2/index.php?p=$1 [NC,QSA,L]

An couple examples of the rewrites I am trying to perform:

  • dev.mydomain.com/services/ => dev.mydomain.com/index.php?p=services

  • dev.mydomain.com/quality/control => dev.mydomain.com/index.php?p=quality/control

Any help/advice you are able to give would be greatly appreciated. I really need to make this work by the end of the day.

The hyphen/dash in a character set functions as a range operator (think 0-9 or az). Having it in the middle or end of can be problematic.

Moving it to the beginning of the character set avoids this issue and means you won't have to escape it with a \\ :

[-a-zA-Z_/]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM