开发者

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|开发者_JAVA百科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 a-z). 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_/]
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜